*********代码的抽取ILBaseTableViewController.h

#import <UIKit/UIKit.h>

@interface ILBaseTableViewController : UITableViewController
@property (nonatomic, strong) NSMutableArray *dataList;
@end

**********ILBaseTableViewController.m

#import "ILBaseTableViewController.h"

#import "ILSettingCell.h"

#import "ILSettingItem.h"

#import "ILSettingArrowItem.h"
#import "ILSettingSwitchItem.h" #import "ILSettingGroup.h" @interface ILBaseTableViewController () @end @implementation ILBaseTableViewController - (NSMutableArray *)dataList
{
if (_dataList == nil) {
_dataList = [NSMutableArray array];
}
return _dataList;
} // 初始化方法
- (id)init
{
return [super initWithStyle:UITableViewStyleGrouped];
} - (void)viewDidLoad
{
[super viewDidLoad]; } #pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{ return self.dataList.count;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{ // Return the number of rows in the section.
ILSettingGroup *group = self.dataList[section];
return group.items.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ // 创建cell
ILSettingCell *cell = [[ILSettingCell class] cellWithTableView:tableView]; // 取出模型
ILSettingGroup *group = self.dataList[indexPath.section];
ILSettingItem *item = group.items[indexPath.row]; // 传递模型
cell.item = item; return cell;
} - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
ILSettingGroup *group = self.dataList[section];
return group.header;
} - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
ILSettingGroup *group = self.dataList[section];
return group.footer;
}
#warning 点击某一行cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{ // 取消选中
[tableView deselectRowAtIndexPath:indexPath animated:YES]; // 取出模型
ILSettingGroup *group = self.dataList[indexPath.section];
ILSettingItem *item = group.items[indexPath.row]; // 执行操作
if (item.option) {
item.option();
return;
} if ([item isKindOfClass:[ILSettingArrowItem class]]) { // 需要跳转控制器
ILSettingArrowItem *arrowItem = (ILSettingArrowItem *)item; // 创建跳转的控制器
if (arrowItem.destVcClass) { UIViewController *vc = [[arrowItem.destVcClass alloc] init];
vc.title = item.title;
[self.navigationController pushViewController:vc animated:YES];
} } } @end

***** ILSettingTableViewController.h

#import <UIKit/UIKit.h>

#import "ILBaseTableViewController.h"

@interface ILSettingTableViewController : ILBaseTableViewController

@end

***** ILSettingTableViewController.m

#import "ILSettingTableViewController.h"

#import "ILSettingCell.h"

#import "ILSettingItem.h"

#import "ILSettingArrowItem.h"
#import "ILSettingSwitchItem.h" #import "ILSettingGroup.h" #import "ILTestViewController.h" #import "MBProgressHUD+MJ.h" #import "ILProductViewController.h" #import "ILPushNoticeController.h" @interface ILSettingTableViewController () @end @implementation ILSettingTableViewController - (void)viewDidLoad
{
[super viewDidLoad]; // 0组
[self addGroup0]; // 1组
[self addGroup1];
}
- (void)addGroup1
{
// 1组
ILSettingItem *newVersion = [ILSettingArrowItem itemWithIcon:@"MoreUpdate" title:@"检查新版本"];
// 保存了一段检查更新的功能
newVersion.option = ^{
// 1.显示蒙板
[MBProgressHUD showMessage:@"正在检查ing......."];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 2.隐藏蒙板
[MBProgressHUD hideHUD]; // 3.提示用户
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"有更新版本" message:nil delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"立即更新", nil];
// 显示UIAlertView
[alert show]; }); };
ILSettingItem *help = [ILSettingArrowItem itemWithIcon:@"MoreHelp" title:@"帮助" destVcClass:[ILTestViewController class]]; ILSettingItem *MoreShare = [ILSettingArrowItem itemWithIcon:@"MoreShare" title:@"分享" destVcClass:[ILTestViewController class]];
ILSettingItem *MoreMessage = [ILSettingArrowItem itemWithIcon:@"MoreMessage" title:@"查看消息" destVcClass:[ILTestViewController class]];
ILSettingItem *MoreNetease = [ILSettingArrowItem itemWithIcon:@"MoreNetease" title:@"产品推荐" destVcClass:[ILProductViewController class]];
ILSettingItem *MoreAbout = [ILSettingArrowItem itemWithIcon:@"MoreAbout" title:@"关于" destVcClass:[ILTestViewController class]]; ILSettingGroup *group1 = [[ILSettingGroup alloc] init];
group1.header = @"帮助";
group1.items = @[newVersion,help,MoreShare,MoreMessage,MoreNetease,MoreAbout]; [self.dataList addObject:group1];
} - (void)addGroup0
{
// 0组
ILSettingArrowItem *pushNotice = [ILSettingArrowItem itemWithIcon:@"MorePush" title:@"推送和提醒" destVcClass:[ILPushNoticeController class]]; ILSettingItem *yaoyiyao = [ILSettingSwitchItem itemWithIcon:@"handShake" title:@"摇一摇机选"]; ILSettingItem *sound = [ILSettingSwitchItem itemWithIcon:@"sound_Effect" title:@"声音效果"]; ILSettingGroup *group0 = [[ILSettingGroup alloc] init];
group0.items = @[pushNotice,yaoyiyao,sound]; [self.dataList addObject:group0];
} @end

*****ILSettingItem.h

#import <Foundation/Foundation.h>

typedef void(^ILSettingItemOption)();

@interface ILSettingItem : NSObject

@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *icon; // 保存一段功能,在恰当的时候调用
@property (nonatomic, copy) ILSettingItemOption option; + (instancetype)itemWithIcon:(NSString *)icon title:(NSString *)title; @end

*****ILSettingItem.m

#import <Foundation/Foundation.h>
typedef void(^ILSettingItemOption)(); @interface ILSettingItem : NSObject @property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *icon; // 保存一段功能,在恰当的时候调用
@property (nonatomic, copy) ILSettingItemOption option; + (instancetype)itemWithIcon:(NSString *)icon title:(NSString *)title; @end

****ILSettingLabelItem .h

#import "ILSettingItem.h"

@interface ILSettingLabelItem : ILSettingItem

// label显示什么内容
@property (nonatomic, copy) NSString *text; @end

***ILSettingLabelItem .m

#import "ILSettingLabelItem.h"

#import "ILSaveTool.h"

@implementation ILSettingLabelItem

- (void)setText:(NSString *)text
{
_text = text; [ILSaveTool setObject:text forKey:self.title];
} - (void)setTitle:(NSString *)title
{
[super setTitle:title]; _text = [ILSaveTool objectForKey:self.title];
} @end

*****view  ILSettingCell.h

#import <UIKit/UIKit.h>

@class ILSettingItem;

@interface ILSettingCell : UITableViewCell

@property (nonatomic, strong) ILSettingItem *item;

+ (instancetype)cellWithTableView:(UITableView *)tableView;

@end

*****view  ILSettingCell.h

#import "ILSettingCell.h"

#import "ILSettingItem.h"

#import "ILSettingArrowItem.h"
#import "ILSettingSwitchItem.h"
#import "ILSettingLabelItem.h" @interface ILSettingCell() @property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UISwitch *switchView;
@property (nonatomic, strong) UILabel *labelView; @end @implementation ILSettingCell - (UILabel *)labelView
{
if (_labelView == nil) {
_labelView = [[UILabel alloc] init];
_labelView.bounds = CGRectMake(, , , );
_labelView.textColor = [UIColor redColor];
_labelView.textAlignment = NSTextAlignmentRight;
}
return _labelView;
} - (UIImageView *)imgView
{
if (_imgView == nil) {
_imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CellArrow"]];
}
return _imgView;
} - (UISwitch *)switchView
{
if (_switchView == nil) { _switchView = [[UISwitch alloc] init];
}
return _switchView;
} - (void)setItem:(ILSettingItem *)item
{
_item = item; // 1.设置cell的子控件的数据
[self setUpData]; // 2.设置右边视图
[self setUpAccessoryView]; } // 设置cell的子控件的数据
- (void)setUpData
{
if (_item.icon.length) { self.imageView.image = [UIImage imageNamed:_item.icon];
}
self.textLabel.text = _item.title;
} // 设置右边视图
- (void)setUpAccessoryView
{
if ([_item isKindOfClass:[ILSettingArrowItem class]]) { // 箭头
self.accessoryView = self.imgView;
self.selectionStyle = UITableViewCellSelectionStyleDefault;
}else if ([_item isKindOfClass:[ILSettingSwitchItem class]]){ // Switch
self.accessoryView = self.switchView;
self.selectionStyle = UITableViewCellSelectionStyleNone;
}else if ([_item isKindOfClass:[ILSettingLabelItem class]]){ //lable
self.accessoryView = self.labelView; ILSettingLabelItem *labelItem = (ILSettingLabelItem *)_item;
self.labelView.text = labelItem.text;
self.selectionStyle = UITableViewCellSelectionStyleDefault;
}else{
self.accessoryView = nil;
self.selectionStyle = UITableViewCellSelectionStyleDefault;
}
} + (instancetype)cellWithTableView:(UITableView *)tableView
{
static NSString *ID = @"cell";
ILSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:ID ]; if (cell == nil) {
cell = [[ILSettingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
} return cell;
} @end

***ILScoreNoticeViewController.m

#import "ILScoreNoticeViewController.h"

#import "ILSettingSwitchItem.h"
#import "ILSettingGroup.h"
#import "ILSettingLabelItem.h" #import "ILSaveTool.h" @interface ILScoreNoticeViewController () @property (nonatomic, strong) ILSettingLabelItem *start; @end @implementation ILScoreNoticeViewController - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. // 0组
[self addGroup0];
// 1组
[self addGroup1];
// 2组
[self addGroup2]; } - (void)addGroup0
{
ILSettingSwitchItem *notice = [ILSettingSwitchItem itemWithIcon:nil title:@"提醒我关注比赛"]; ILSettingGroup *group = [[ILSettingGroup alloc] init];
group.items = @[notice];
group.footer = @"asdsad";
[self.dataList addObject:group];
} - (void)addGroup1
{
ILSettingLabelItem *start = [ILSettingLabelItem itemWithIcon:nil title:@"开始时间"];
_start = start; if (!start.text.length) {
start.text = @"00:00";
} start.option = ^{
UITextField *textField = [[UITextField alloc] init]; UIDatePicker *datePicker = [[UIDatePicker alloc] init];
// 设置模式
datePicker.datePickerMode = UIDatePickerModeTime; // 设置地区
datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh"]; // 创建日期格式对象
NSDateFormatter *dateF = [[NSDateFormatter alloc] init];
dateF.dateFormat = @"HH:mm";
// 设置日期
datePicker.date = [dateF dateFromString:@"00:00"]; // 监听UIDatePicker
[datePicker addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventValueChanged]; // 设置键盘
textField.inputView = datePicker; [textField becomeFirstResponder];
[self.view addSubview:textField]; };
ILSettingGroup *group = [[ILSettingGroup alloc] init];
group.items = @[start];
group.header = @"";
[self.dataList addObject:group];
} - (void)valueChange:(UIDatePicker *)datePicker
{
// 创建日期格式对象
NSDateFormatter *dateF = [[NSDateFormatter alloc] init];
dateF.dateFormat = @"HH:mm";
_start.text = [dateF stringFromDate:datePicker.date]; //设置数据 刷新 [self.tableView reloadData];
}
- (void)addGroup2
{
ILSettingLabelItem *stop = [ILSettingLabelItem itemWithIcon:nil title:@"结束时间"];
stop.text = @"00:00";
ILSettingGroup *group = [[ILSettingGroup alloc] init];
group.items = @[stop]; //加入组 [self.dataList addObject:group]; //把组加入集合
}
@end

***ILScoreNoticeViewController.h

#import "ILBaseTableViewController.h"

@interface ILScoreNoticeViewController : ILBaseTableViewController

@end

***ILPushNoticeController .h

#import <UIKit/UIKit.h>

#import "ILBaseTableViewController.h"

@interface ILPushNoticeController : ILBaseTableViewController

@end

***ILPushNoticeController .m

#import "ILPushNoticeController.h"

#import "ILSettingCell.h"

#import "ILSettingItem.h"

#import "ILSettingArrowItem.h"
#import "ILSettingSwitchItem.h" #import "ILSettingGroup.h" #import "ILScoreNoticeViewController.h" @interface ILPushNoticeController () @property (nonatomic, strong) NSMutableArray *dataList; @end @implementation ILPushNoticeController - (void)viewDidLoad
{
[super viewDidLoad]; // 0组
[self addGroup0]; } - (void)addGroup0
{ // 0组
ILSettingArrowItem *push = [ILSettingArrowItem itemWithIcon:nil title:@"开奖号码推送" destVcClass:nil]; ILSettingItem *anim = [ILSettingArrowItem itemWithIcon:nil title:@"中奖动画"]; ILSettingItem *score = [ILSettingArrowItem itemWithIcon:nil title:@"比分直播" destVcClass:[ILScoreNoticeViewController class]];
ILSettingItem *timer = [ILSettingArrowItem itemWithIcon:nil title:@"购彩定时提醒"]; ILSettingGroup *group0 = [[ILSettingGroup alloc] init];
group0.items = @[push,anim,score,timer]; [self.dataList addObject:group0]; } @end

****ILSettingArrowItem.m

#import "ILSettingArrowItem.h"

@implementation ILSettingArrowItem

+ (instancetype)itemWithIcon:(NSString *)icon title:(NSString *)title destVcClass:(Class)destVcClass
{
ILSettingArrowItem *item = [super itemWithIcon:icon title:title];
item.destVcClass = destVcClass; return item;
} @end

*****ILProductViewController.h

#import <UIKit/UIKit.h>

@interface ILProductViewController : UICollectionViewController

@end

*****ILProductViewController.m

#import "ILProductViewController.h"

#import "ILProduct.h"
#import "ILProductCell.h" @interface ILProductViewController () @property (nonatomic, strong) NSMutableArray *products; @end @implementation ILProductViewController - (NSMutableArray *)products
{
if (_products == nil) {
_products = [NSMutableArray array]; NSString *fileName = [[NSBundle mainBundle] pathForResource:@"products.json" ofType:nil];
NSData *data = [NSData dataWithContentsOfFile:fileName]; NSArray *jsonArr = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; for (NSDictionary *dict in jsonArr) {
ILProduct *product = [ILProduct productWithDict:dict];
[_products addObject:product];
} }
return _products;
} static NSString *ID = @"product"; /*
使用UICollectionView
第一步:必须有布局
第二部:cell必须自己注册 */ - (id)init
{
// 创建流水布局
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; // 每一个cell的尺寸
layout.itemSize = CGSizeMake(, ); // 垂直间距
layout.minimumLineSpacing = ; // 水平间距
layout.minimumInteritemSpacing = ; // 内边距
layout.sectionInset = UIEdgeInsetsMake(, , , ); return [super initWithCollectionViewLayout:layout];
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. // 注册UICollectionViewCell,如果没有从缓存池找到,就会自动帮我们创建UICollectionViewCell
UINib *xib = [UINib nibWithNibName:@"ILProductCell" bundle:nil]; [self.collectionView registerNib:xib forCellWithReuseIdentifier:ID];
// [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:ID]; self.collectionView.backgroundColor = [UIColor whiteColor];
} // 数据源
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return ;
} - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return self.products.count;
} // 返回每一个cell长什么样
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{ ILProductCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath]; // 获取模型
ILProduct *p = self.products[indexPath.item]; cell.product = p; return cell;
} - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
ILProduct *p = self.products[indexPath.item];
NSLog(@"点击了---%@",p.title);
} @end

******ILProduct.h

#import "ILProduct.h"

@implementation ILProduct

+ (instancetype)productWithDict:(NSDictionary *)dict{
ILProduct *product = [[ILProduct alloc] init]; product.title = dict[@"title"];
product.icon = dict[@"icon"];
product.url = dict[@"url"];
product.customUrl = dict[@"customUrl"];
product.ID = dict[@"id"]; return product;
} - (void)setIcon:(NSString *)icon
{
_icon = [icon stringByReplacingOccurrencesOfString:@"@2x.png" withString:@""]; } @end

******ILProduct.m

#import <Foundation/Foundation.h>
/*
{
"title": "网易电影票",
"id": "com.netease.movie",
"url": "http://itunes.apple.com/app/id583784224?mt=8",
"icon": "movie@2x.png",
"customUrl": "movieticket163"
}, */
@interface ILProduct : NSObject @property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *ID;
@property (nonatomic, copy) NSString *url;
@property (nonatomic, copy) NSString *icon;
@property (nonatomic, copy) NSString *customUrl; + (instancetype)productWithDict:(NSDictionary *)dict; @end

IOS彩票第二天设置界面(2)的更多相关文章

  1. IOS彩票第二天设置界面(1)

    ****跳转到设置界面 - (IBAction)setting:(id)sender { // 创建设置口控制器 ILSettingTableViewController *settingVc = [ ...

  2. iOS提醒用户进入设置界面进行重新授权通知定位等功能

    iOS 8及以上版本最不为人知的一个特点是与应用设置的深层链接,用户可以根据APP的需要授权启用位置.通知.联系人.相机.日历以及健康等设置. 大多数应用程序仅仅是弹出一个包含操作指令的警示窗口,如“ ...

  3. iOS APP跳转设置界面以及设置中的其他界面

    1.跳转设置总页面(iOS10+以及之前的都可以用:ios10+ 是跳转到了应用到设置界面) [[UIApplication sharedApplication]openURL:[NSURL URLW ...

  4. IOS彩票第三天界面

    ******ios6 和ios7的适配 ILBaseTableViewController.m - (void)viewDidLoad { [super viewDidLoad]; // 244 24 ...

  5. iOS开发——开发必备OC篇&UITableView设置界面完整封装(二)

    UITableView设置界面完整封装(二) 简单MVC实现UITableView设置界面之Cell右边类型设置 首先来看看第一种方法证明使用,结合两种方法之后根据个人的爱好去选择就可以了, 一:使用 ...

  6. iOS开发 - 如何跳到系统设置里的各种设置界面

    在iOS开发中,有时会有跳转系统设置界面的需求,例如提示用户打开蓝牙或者WIFI,提醒用户打开推送或者位置权限等.在iOS6之后,第三方应用需要跳转系统设置界面,需要在URL type中添加一个pre ...

  7. iOS开发之如何跳到系统设置里的各种设置界面

    跳到更多设置界面 除了跳到WiFi设置界面,能不能跳到其他的设置界面呢?比如:定位服务.FaceTime.音乐等等.都是可以的,一起来看看如何实现的! 定位服务 定位服务有很多APP都有,如果用户关闭 ...

  8. iOS 跳转到系统的设置界面

    跳到健康设置   上网找了一下  你会发现很难找到.代码如下  不信你试试 . NSURL *url = [NSURL URLWithString:@"prefs:root=Privacy& ...

  9. iOS开发——开发必备OC篇&UITableView设置界面完整封装(四)

    设置界面完整封装(四) 简单MVC实现UITableView设置界面完善封装及拓展使用 关于使用和拓展, 其实基本上就是同UItableView,知识讲数据改一下就可以 拓展使用 1:首先定义一个数组 ...

随机推荐

  1. Swift3.0语言教程字符串与文件的数据转换

    Swift3.0语言教程字符串与文件的数据转换 Swift3.0语言教程字符串与文件的数据转换,如果想要对字符串中的字符进行永久保存,可以将字符串中的字符写入到文件中.当然,开发者也可以将写入的内容进 ...

  2. 基于netty的微服务架构

    基于netty的微服务架构 微服务一篇好文章 http://san-yun.iteye.com/blog/1693759 教程 http://udn.yyuap.com/doc/essential-n ...

  3. 并查集 + 线段树 LA 4730 Kingdom

    题目传送门 题意:训练指南P248 分析:第一个操作可以用并查集实现,保存某集合的最小高度和最大高度以及城市个数.运用线段树成端更新来统计一个区间高度的个数,此时高度需要离散化.这题两种数据结构一起使 ...

  4. 我认为我可以去尝试做一下Maya Ue4导出插件

    Begin Map Begin Level Begin Actor class="StaticMeshActor" Name=Floor Archetype=StaticMeshA ...

  5. Java NIO示例:多人网络聊天室

    一个多客户端聊天室,支持多客户端聊天,有如下功能: 功能1: 客户端通过Java NIO连接到服务端,支持多客户端的连接 功能2:客户端初次连接时,服务端提示输入昵称,如果昵称已经有人使用,提示重新输 ...

  6. CF#335 Sorting Railway Cars

    Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  7. Oracle存储过程中临时表的使用技巧

    一.Oracle临时表知识 在Oracle中,临时表分为SESSION(会话级).TRANSACTION(事务级)两种,SESSION级的临时表数据在整个SESSION都存在,直到结束此次SESSIO ...

  8. CentOS6.4 安装OpenResty和Redis 并在Nginx中利用lua简单读取Redis数据

    1.下载OpenResty和Redis OpenResty下载地址:wget http://openresty.org/download/ngx_openresty-1.4.3.6.tar.gz Re ...

  9. APP测试流程

    1 APP测试基本流程 1.1流程图 1.2测试周期 测试周期可按项目的开发周期来确定测试时间,一般测试时间为两三周(即15个工作日),根据项目情况以及版本质量可适当缩短或延长测试时间.正式测试前先向 ...

  10. [知识点]网络流之Dinic算法

    // 此博文为迁移而来,写于2015年2月6日,不代表本人现在的观点与看法.原始地址:http://blog.sina.com.cn/s/blog_6022c4720102vrg4.html      ...