iOS彩票项目--第六天,运用MVC思想搭建设置界面(非storyboard方法)
一、我只想说封装的思想很重要,MVC的思想也很重要,利用MVC思想搭建一下的界面
- 先说显示出来的cell,有三种(图中的两种,还有一种是最普通的,没有图片的),这种显示不同的cell,交给模型来处理,模型中的数据决定了要显示的样式。
- 但是有考虑到功能的不一样,所以运用了面向对象的思想,同时继承自cell,实现具体到每一种会有单独的样式和功能。
- 不同的样式只要根据类名来判断,展示不同的效果。
- 初始化cell,通过类名来判断是带箭头的cell还是带开关的cell
@interface ChaosSettingCell ()
/** arrow */
@property(nonatomic,strong) UIImageView *arrowView;
/** switch */
@property(nonatomic,strong) UISwitch *switchView;
@end
@implementation ChaosSettingCell - (UIImageView *)arrowView
{
if (_arrowView == nil) {
_arrowView = [[UIImageView alloc]initWithImage: [UIImage imageNamed:@"arrow_right"]];
}
return _arrowView;
} - (UISwitch *)switchView
{
if (_switchView == nil) {
_switchView = [[UISwitch alloc]init];
}
return _switchView;
} #pragma mark - 自定义cell内部实现,,返回cell的方法
+ (ChaosSettingCell *)cellWithTableView:(UITableView *)tableView style:(UITableViewCellStyle)style
{
static NSString *ID = @"cell"; ChaosSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
if (cell == nil) {
cell = [[ChaosSettingCell alloc] initWithStyle:style reuseIdentifier:ID];
}
return cell;
} // 重写cell的set方法,给cell赋值
- (void)setItem:(ChaosSettingItem *)item
{
_item = item; [self setUpData]; [self setUpAccessoryView];
} // 给cell绑定数据
- (void)setUpData
{
self.imageView.image = self.item.icon;
self.textLabel.text = self.item.title;
self.detailTextLabel.text = self.item.subTitle;
}
// 设置cell的辅助视图
- (void)setUpAccessoryView
{
if ([self.item isKindOfClass:[ChaosSettingItemArrow class]]) { // 箭头 self.accessoryView = self.arrowView; } else if([self.item isKindOfClass:[ChaosSettingItemSwitch class]]){ // 开关 self.accessoryView = self.switchView;
self.selectionStyle = UITableViewCellSelectionStyleNone; } else { // 还原 self.accessoryView = nil;
self.selectionStyle = UITableViewCellSelectionStyleDefault;
}
} @end
- 通过设置不同的模型,完全实现了展示的效果
#import "ChaosSettingViewController.h"
#import "ChaosHelpViewController.h"
#import "ChaosSettingGroup.h" #import "ChaosPushViewController.h"
#import "ChaosHelpViewController.h" #import "ChaosBlurView.h"
#import "MBProgressHUD+XMG.h" @interface ChaosSettingViewController () @end @implementation ChaosSettingViewController - (instancetype)init
{
return [super initWithStyle:UITableViewStyleGrouped];
} - (void)viewDidLoad {
[super viewDidLoad]; self.title = @"设置";
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"常见问题" style:UIBarButtonItemStyleBordered target:self action:@selector(help)]; [self setUpGroup0];
[self setUpGroup1];
[self setUpGroup2];
} - (void)help
{
ChaosHelpViewController *helpVC = [[ChaosHelpViewController alloc] init]; helpVC.title = @"帮助"; [self.navigationController pushViewController:helpVC animated:YES];
} - (void)setUpGroup0
{
ChaosSettingItemArrow *item = [ChaosSettingItemArrow itemWithImage:[UIImage imageNamed:@"RedeemCode"] title:@"使用兑换码"];
item.pushVCName = [UITableViewController class];
NSArray *items = @[item];
ChaosSettingGroup *group = [ChaosSettingGroup groupWithHeader:nil footer:nil items:items];
[self.sections addObject:group];
}
- (void)setUpGroup1
{
ChaosSettingItemArrow *item = [ChaosSettingItemArrow itemWithImage:[UIImage imageNamed:@"MorePush"] title:@"推送和提醒"]; item.pushVCName = [ChaosPushViewController class]; ChaosSettingItemSwitch *item1 = [ChaosSettingItemSwitch itemWithImage:[UIImage imageNamed:@"more_homeshake"] title:@"摇一摇机选"];
ChaosSettingItemSwitch *item2 = [ChaosSettingItemSwitch itemWithImage:[UIImage imageNamed:@"sound_Effect"] title:@"声音效果"];
ChaosSettingItemSwitch *item3 = [ChaosSettingItemSwitch itemWithImage:[UIImage imageNamed:@"More_LotteryRecommend"] title:@"采购小助手"];
NSArray *items = @[item,item1,item2,item3];
ChaosSettingGroup *group = [ChaosSettingGroup groupWithHeader:nil footer:nil items:items];
[self.sections addObject:group];
}
- (void)setUpGroup2
{
ChaosSettingItemArrow *item = [ChaosSettingItemArrow itemWithImage:[UIImage imageNamed:@"MoreUpdate"] title:@"检查新版本"];
item.itemOpertion = ^(NSIndexPath *indexPath){
// 高斯模糊框架的应用
ChaosBlurView *blurView = [[ChaosBlurView alloc] initWithFrame:ChaosScreenBounds];
[ChaosKeyWindow addSubview:blurView]; [MBProgressHUD showSuccess:@"没有新版本可更新"]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)( * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[blurView removeFromSuperview];
}); };
ChaosSettingItemArrow *item1 = [ChaosSettingItemArrow itemWithImage:[UIImage imageNamed:@"MoreShare"] title:@"分享"];
ChaosSettingItemArrow *item2 = [ChaosSettingItemArrow itemWithImage:[UIImage imageNamed:@"MoreNetease"] title:@"产品推荐"];
ChaosSettingItemArrow *item3 = [ChaosSettingItemArrow itemWithImage:[UIImage imageNamed:@"MoreAbout"] title:@"关于"];
NSArray *items = @[item,item1,item2,item3];
ChaosSettingGroup *group = [ChaosSettingGroup groupWithHeader:nil footer:nil items:items];
[self.sections addObject:group];
} @end
- 模型中的
/** itemblock */
@property(nonatomic,strong) void(^itemOpertion)(NSIndexPath *indexPath); 这个属性用来保存代码段。项目中是点击了相应的cell后需要做的事情保存到了block中
iOS彩票项目--第六天,运用MVC思想搭建设置界面(非storyboard方法)的更多相关文章
- iOS彩票项目--第三天,搭建竞技场和发现,搭建幸运选号和我的彩票界面
一.竞技场搭建--UISegmentedControl的使用 // 重写 自定义控制器的view - (void)loadView { UIImageView *imgView = [[UIImage ...
- iOS彩票项目--第四天,新特性界面搭建,UICollectionViewController的初次使用
一.新特性界面搭建的思路: 在AppDelegate加载主窗体的时候进行判断程序版本号,直接进入程序或者进入新特性展示界面 取出当前的版本号,与旧的版本号相比较(旧的版本号在进入程序的时候存起来 =& ...
- iOS彩票项目--第一天,自定义TabBar控制器和自定义TabBar,自定义导航控制器
一.环境配置,和项目层次搭建 二.自定义TabBar 项目中TabBar中的导航按钮美工给的图片太大,图片中包含了图片和文字.最主要的是TabBar上面的按钮图片尺寸是有规定的,当高度大于44的时候, ...
- iOS彩票项目--第七天,初次读取json数据、KVC转模型技巧、运行时字典转模型以及初步对显示网页的操作并且跟踪标签
一.初次读取json数据 二.KVC转模型技巧,这里的技巧主要解决的是字典中的key 与 模型中有的属性对应不起来的时候 的解决办法 <方法1> <方法2>运行时字典转模型,运 ...
- iOS彩票项目--第五天,新特性引导页的封装、返回按钮的自定义、导航控制器的滑动返回以及自定义滑动返回功能
一.上次实现了在AppDelegate中通过判断app版本决定是否进入新特性页面,今天将AppDelegate中的一坨进行了封装.将self.window的根控制器到底应该为新特性界面,还是主页面,封 ...
- iOS彩票项目--第二天,自定义蒙版、封装活动菜单、自定义pop菜单
一.自定义蒙版--封装控件,先想好外界怎么来调用,根据外界调用的方法,然后进入内部实现 在外部,调用蒙版的方法--[ChaosCover show]; [ChaosCover hide]; 内部实现 ...
- ASP.NET中彩票项目中的计算复式投注的注数的方法
从别人做的项目中抽取出的代码:
- iOS开发——项目篇—高仿百思不得姐 05——发布界面、发表文字界面、重识 bounds、frame、scrollView
加号界面(发布模块) 一.点击加号modal出发布模块,创建控件,布局控件1)使用xib加载view,如果在viewDidLoad创建控件并设置frame 那么self.view 的宽高 拿到的是xi ...
- iOS如何跳到系统设置里的各种设置界面
最近项目需要授权时候跳转到相关的设置页面,自己总结了一下,想写到简书上来,和大家分享一下. 在本人测试后,iOS8和9都没有问题,直接跳转到各个页面,这可能苹果对这方面开放了吧.第一步修改plist文 ...
随机推荐
- SDUT 2608 Alice and Bob (巧妙的二进制)
Alice and Bob Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Alice and Bob like playing ...
- 微信小程序四(设置底部导航)
好了 小程序的头部标题 设置好了,我们来说说底部导航栏是如何实现的. 我们先来看个效果图 这里,我们添加了三个导航图标,因为我们有三个页面,微信小程序最多能加5个. 那他们是怎么出现怎么着色的呢?两步 ...
- oc Delegate
把内部的状态通知给外界,我们可以制定一个变量,然后这个变量从外界来指定,之后我们可以通过变量去通知给外界有什么发生了. 按照上文讲的到新建一个protocol,名字为IPeople #import & ...
- VC++获取操作系统的版本 GetVersionEx函数
原文链接: http://blog.sina.com.cn/s/blog_8a7012cf010189tn.html 函数:BOOL CSystemOperate::GetOSDisplayStrin ...
- background-image:url(data:image/gif;base64,XXXX) base64方式将本地图片添加到文档中
background-image:url(data:image/gif;base64,R0lGODlhCwAMAMZjAElxvlNvtVRxtkp1v0p9wVh7vkqBwl58vml6vml7v ...
- sql 跨表修改的方式
update xhj_mon_job_log a set person_id = (select id from xhj_mon_job_manage b where a.task_id = b.id ...
- activiti自己定义流程之Spring整合activiti-modeler实例(一):环境搭建
项目中须要整合activiti-modeler自己定义流程,找了非常多资料后,最终成功的跳转到activiti-modeler流程设计界面.下面是记录: 一.整合基础:eclipse4.4.1.tom ...
- mybatis 一二事(3) - 多表关联查询
db.properties jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/order jdbc.user ...
- Diamond 3.5简易教程(二)------软件的简单使用
二.软件的简单使用 工程建立后我们就可以进行程序的编写添加了. 选择左下角file list 选项卡 这里主要是工程的信息. 在input files 上右键弹出选项addànew file... 在 ...
- 【Android】7.5 RelativeLayout(相对布局)
分类:C#.Android.VS2015: 创建日期:2016-02-11 一.简介 RelativeLayout是一种相对布局,容器中子元素的位置是相对于其前一个元素或者其他元素的位置来计算的,或者 ...