IOS彩票第二天设置界面(2)
*********代码的抽取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)的更多相关文章
- IOS彩票第二天设置界面(1)
****跳转到设置界面 - (IBAction)setting:(id)sender { // 创建设置口控制器 ILSettingTableViewController *settingVc = [ ...
- iOS提醒用户进入设置界面进行重新授权通知定位等功能
iOS 8及以上版本最不为人知的一个特点是与应用设置的深层链接,用户可以根据APP的需要授权启用位置.通知.联系人.相机.日历以及健康等设置. 大多数应用程序仅仅是弹出一个包含操作指令的警示窗口,如“ ...
- iOS APP跳转设置界面以及设置中的其他界面
1.跳转设置总页面(iOS10+以及之前的都可以用:ios10+ 是跳转到了应用到设置界面) [[UIApplication sharedApplication]openURL:[NSURL URLW ...
- IOS彩票第三天界面
******ios6 和ios7的适配 ILBaseTableViewController.m - (void)viewDidLoad { [super viewDidLoad]; // 244 24 ...
- iOS开发——开发必备OC篇&UITableView设置界面完整封装(二)
UITableView设置界面完整封装(二) 简单MVC实现UITableView设置界面之Cell右边类型设置 首先来看看第一种方法证明使用,结合两种方法之后根据个人的爱好去选择就可以了, 一:使用 ...
- iOS开发 - 如何跳到系统设置里的各种设置界面
在iOS开发中,有时会有跳转系统设置界面的需求,例如提示用户打开蓝牙或者WIFI,提醒用户打开推送或者位置权限等.在iOS6之后,第三方应用需要跳转系统设置界面,需要在URL type中添加一个pre ...
- iOS开发之如何跳到系统设置里的各种设置界面
跳到更多设置界面 除了跳到WiFi设置界面,能不能跳到其他的设置界面呢?比如:定位服务.FaceTime.音乐等等.都是可以的,一起来看看如何实现的! 定位服务 定位服务有很多APP都有,如果用户关闭 ...
- iOS 跳转到系统的设置界面
跳到健康设置 上网找了一下 你会发现很难找到.代码如下 不信你试试 . NSURL *url = [NSURL URLWithString:@"prefs:root=Privacy& ...
- iOS开发——开发必备OC篇&UITableView设置界面完整封装(四)
设置界面完整封装(四) 简单MVC实现UITableView设置界面完善封装及拓展使用 关于使用和拓展, 其实基本上就是同UItableView,知识讲数据改一下就可以 拓展使用 1:首先定义一个数组 ...
随机推荐
- PHP学习之字符串
1.字符串变量用于存储并处理文本: 2.字符串变量用于包含有字符的值,在创建字符串后,就可以对它进行操作了,可以直接在函数中使用字符串,或把它存储在变量中: <?php $txt="H ...
- JavaScript 之 iframe自适应问题---可以用来实现网页局部刷新
1.HTML <iframe src="index.html" id="iframepage" frameborder="0" scr ...
- 《DSP using MATLAB》示例Example4.15
代码: b = [1/3, 1/3, 1/3]; a = [1, -0.95, 0.9025]; % x(n) y(n) coefficient [R, p, C] = residuez(b,a) M ...
- DOM--5 动态修改样式和层叠样式表
W3C DOM2 样式规范 CSSStyleSheet对象 表示所有css样式表,包括外部link和嵌入style的;通过document.styleSheets属性可以获得文档中CSSStyleSh ...
- CSS3-animation,表格表单的格式化
animation 1.与transition一样,animation在IE9之前都不支持,不仅如此,还需要大量的供应商前缀 2.定义关键帧:@内容中需要大量的前缀 @keyframes fadeI ...
- BeanShell用法汇总(部分摘抄至网络)【转】
说明:本文部分资料摘抄至 来源: http://www.cnblogs.com/puresoul/p/4915350.html 来源: http://www.cnblogs.com/puresoul/ ...
- iOS 初学UITableView、UITableViewCell、Xib
注意事项: 1.一个.xib里面最多设置一个cell 2.要仔细调整自动布局,其实它不太好用 3.记得设置<UITableViewDataSource>委托 4.记得在ViewContro ...
- 【转】敏捷开发 Scrum 总结
转:http://www.open-open.com/lib/view/open1330413325514.html 最近把之前学习 Scrum 的资料整理为一篇文档,在接下来的团队和项目开发中,根据 ...
- hdu 1312 Red and Black
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored eit ...
- Leetcode Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...