1. 点击“cell”推出对应的界面缓存
1.1 新建group,名为:Settingide
路径:MYLottery(个人彩票)->Controller字体
1.2 新建Cocoa Touch Class,名为:HMRedeemControlleratom
路径:MYLottery(个人彩票)->Controller->Setting->spa
Cocoa Touch Class:(Class:HMRedeemController;Subclass of:UIViewController;Language:Objective-C)3d
1.3 在“HMRedeemController.m”的“viewDidLoad”方法中设置“View Controller”的背景为紫色,代码以下:code
- (void)viewDidLoad { self.view.backgroundColor = [UIColor purpleColor]; }
1.4 在“HMSettingController.m”建立点击“cell”调用方法,代码以下:orm
//点击 cell 调用 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //获取组 NSDictionary *group = self.groups[indexPath.section]; //获取组全部的 cell NSArray *items = group[@"items"]; //获取 cell 的信息 NSDictionary *item = items[indexPath.row]; if (item[@"targetVC"] && [item[@"targetVC"] length] > 0 ]) { //获取字符串类型的目标 NSString *targetVC = item[@"targetVC"]; //转换为 Class 的类型 Class Clz = NSClassFromString(targetVC); //Class 的类型的对象 UIViewController *vc = [[Clz alloc] init]; if ([vc isKindOfClass:[HMSettingController class]]) { //若是是 setting 类型,须要传入一个 plistName HMSettingController *setting = (HMSettingController *)vc; setting.plishName = item[@"plistName"]; } //设置 title vc.navigationItem.title = item[@"title"]; //跳转 [self.navigationControler pushViewController:vc animated:YES]; } }
2. 点击“推送和提醒”推出对应的界面对象
2.1 修改“plist”获取方法blog
2.1.1 在“HMSettingController.h”申明“plistName”属性,
代码以下:@property (nonatomic, copy) NSString *plistName;
2.1.2 在“HMSettingController.m”修改“plist”获取方法
原码:NSString *path = [[NSBundle mainBundle] pathForResource:@“Setting” ofType:@"plist"];
修改:NSString *path = [[NSBundle mainBundle] pathForResource:self.plistName ofType:@"plist"];
2.1.3 在“HMMyLotteryController.m”的“settingClick”方法添加“plist”获取属性
代码以下:setting.plistName = @"Setting";
2.2 重写“init”方法
2.2.1 在“HMSettingController.m”新建重写“init”方法
- (instancetype)init { return [super initWithStyle:UITableViewStyleGrouped]; } - (instancetype)initWithStyle:(UITableViewStyle)style { return [super initWithStyle:UITableViewStyleGrouped]; }
2.1.2 在“HMMyLotteryController.m”修改“Table View”的“init”方法
原码:HMSettingController *setting = [[HMSettingController alloc] initWithStyle:UITableViewStyleGrouped];
修改:HMSettingController *setting = [[HMSettingController alloc] init];
2.3 新建Property List,名为:SettingPush
路径:MYLottery(个人彩票)->Other
2.4 在“HMSettingController.m”修改加载“cell”图片属性
原码:cell.imageView.image = [UIImage imageNamed:item[@"icon"]];
修改:if (item[@"icon"] && [item[@"icon"] length] > 0) {
//设置 cell 图片
cell.imageView.image = [UIImage imageNamed:item[@"icon"]];
}
2.5 将“HMSettingController.m”类中的“viewDidLoad”方法中的“self.navigationControler.title = @"设置";”
剪切到“HMMyLotteryController.m”类中的“settingClick”方法中
3. “推送和提醒”的“开奖推送”界面
3.1 新建Property List,名为:SettingPush01
路径:MYLottery(个人彩票)->Other
3.2 在“HMSettingController.m”建立 cell 返回类型,代码以下:
//根据传入的 cell 类型,返回须要建立的 cell 的类型 - (UITableViewCellStyle)loadCellStyleWithItem:(NSDictionary *)item { if ([item[@"cellType"] isEqualToString:@"UITableViewCellStyleSubtitle"]) { return UITableViewCellStyleSubtitle; } else if ([item[@"cellType"] isEqualToString:@"UITableViewCellStyleValue1"]) { return UITableViewCellStyleValue1; } else if ([item[@"cellType"] isEqualToString:@"UITableViewCellStyleValue2"]) { return UITableViewCellStyleValue2; } else { return UITableViewCellStyleDefault; } }
3.3 在“HMSettingController.m”类中的“UITableViewCell”方法中修改 cell 建立类型方式
原码:cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
修改:cell = [[UITableViewCell alloc] initWithStyle:[self loadCellStyleWithItem:item] reuseIdentifier:cellid];
3.4 在“HMSettingController.m”类中的“UITableViewCell”添加 cell 的子标题
代码以下:cell.detailTextLabel.text = item[@"subTitle"];
4. 封装 cell
4.1 新建Cocoa Touch Class,名为:HMSettingCell
路径:MYLottery(个人彩票)->View->
Cocoa Touch Class:(Class:HMSettingCell;Subclass of:UITableViewCell;Language:Objective-C)
4.2 在“HMSettingCell.h”申明"item"字典和“settingCellWithTableView”类方法,
代码以下:
@property (nonatomic, strong) NSDictionary *item;
+ (instancetype)settingCellWithTableView:(UITableView *)tableView andItem:(NSDictionary *)item;
4.3 在“HMSettingCell.m”实现“settingCellWithTableView”类方法,
将“HMMyLotteryController.m”相关代码剪切到该文件修改,代码以下:
@implementation HMSettingCell + (instancetype)settingCellWithTableView:(UITableView *)tableView andItem:(NSDictionary *)item { //static NSString *cellid = @"setting_cell"; //cell 重用 NSString *cellid = @""; if (item[@"cellType"] && [item[@"cellType"] length] > 0) { cellid = item[@"cellType"]; } else { cellid = @"setting_cell"; } //缓存池找 HMSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid]; if (!cell) { cell = [[HMSettingCell alloc] initWithStyle:[self loadCellStyleWithItem] reuseIdentifier:cellid]; } cell.item = item; return cell; } - (void)setItem:(NSDictionary *)item { _item = item; //把数据放到 cell //赋值 if (item[@"icon"] && [item[@"icon"] length] > 0) { self.imageView.image = [UIImage imageNamed:item[@"icon"]]; //设置图片 } self.textLabel.text = item[@"title"]; //设置标题 self.detailTextLabel.text = item[@"subTitle"]; //设置子标题 //根据字符建立生成对象 NSString *accessoryType = item[@"accessoryType"]; //获取 UISwith 的字符串:@"UISwith" Class Clz = NSClassFromString(accessoryType); //获取 UISwith 的类型:UISwith UIView *obj = [[Clz alloc] init]; //获取 UISwith 类型的对象 //判断 obj 真实的类型 if ([obj isKindOfClass:[UIImage class]]) { //设置 frame 图片 UIImageView *imageView = (UIImageView *)obj; imageView.image = [UIImage imageNamed:item[@"accessoryContent"]]; [imageView sizeToFit]; } self.accessoryType = obj; //设置 accessoryView } //根据传入的 cell 类型,返回须要建立的 cell 的类型 - (UITableViewCellStyle)loadCellStyleWithItem:(NSDictionary *)item { if ([item[@"cellType"] isEqualToString:@"UITableViewCellStyleSubtitle"]) { return UITableViewCellStyleSubtitle; } else if ([item[@"cellType"] isEqualToString:@"UITableViewCellStyleValue1"]) { return UITableViewCellStyleValue1; } else if ([item[@"cellType"] isEqualToString:@"UITableViewCellStyleValue2"]) { return UITableViewCellStyleValue2; } else { return UITableViewCellStyleDefault; } } @end
5. “推送和提醒”的“比分直播推送”界面
5.1 新建Cocoa Touch Class,名为:HMLiveController
路径:MYLottery(个人彩票)->Controller->Setting->
Cocoa Touch Class:(Class:HMLiveController;Subclass of:UISettingController;Language:Objective-C)
5.2 配置“SettingPush.plish”
Item 1->“plistName”:SettingPush02
Item 1->“targetVC”:“HMLiveController”
5.3 新建Property List,名为:SettingPush02
路径:MYLottery(个人彩票)->Other
5.4 设置“起始时间”和“结束时间”的时间字体为红色
在“HMSettingCell.m”类的“setItem”方法中添加子标题颜色方法,代码以下:
if ([item[@"isRed"] boolValue] && item[@"isRed"]) { self.detaiTextLabel.textColor = [UIColor redColor]; //设置子标题颜色 }
5.5 点击“起始时间”和“结束时间” cell 弹出文本框
5.5.1 在“HMLiveController.m”中申明“datePlicker”的全局变量
代码以下:@property (nonatomic, weak) UIDatePicker *datePicker;
5.5.2 在“HMLiveController.m”中建立 cell 点击事件,代码以下:
#import "UIView_Frame.h" - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //第一组不点 if (indexPath.section == 0) { return; } //建立一个看不见的文本框 UITextField *text = [[UITextField alloc] init]; //建立 cell UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; //添加到 cell 上 [cell.contentView addSubview:text]; //建立 datePicker UIDatePicker.locale = [[UIDatePicker alloc] init]; self.datePicker = datePicker; //中文 datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"]; //时间模式 datePicker.datePickerMode = UIDatePickerModeTime; //设置文本框的 inputView text.inputView = datePicker; //建立 toolbar UIToolbar * bar = [[UIToolbar alloc] init]; //设置 toolbar 的高度 bar.h = 44; //建立三个 item //item - 取消 UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancelClick)]; //item - 弹簧 UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonItemStyleItemFlexibleSpace target:nil action:nil]; //item - 完成 UIBarButtonItem *doneItem = [[UIBarButtonItem alloc] initWithTitle:@"完成" style:UIBarButtonItemStyleDone target:self action:@selector(doneClick)]; //设置 toolbar 的 item bar.items = @[cancelItem, item, doneItem]; //设置文本框的 imputAccessoryView text.inpushAccessoryView = bar; //让文本框成为第一响应者 [text becomeFirstResponder]; }
5.5.3 在“HMLiveController.m”中建立 toolbar 取消按钮的点击事件,代码以下:
//收键盘 - (void)cancelClick { [self.view endEditing:YES]; }
5.5.4 在“HMLiveController.m”中建立 toolbar 完成按钮的点击事件,代码以下:
- (void)doneClick { //获取 datePicker 的时间 NSDate *date = self.datePicker.date; //建立格式化时间的对象 NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; //设置格式化时间对象的格式 formatter.dateFormat = @"HH:mm"; //把 date 转成 string NSString *time = [formatter stringFromFate:date]; //获取 indexPath NSIndexPath *path = [self.tableView indexPathForSelectedRow]; //获取 cell UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:path]; //修改时间 cell.detaiTextLabel.text = time; //收键盘 [self cancelClick]; }