1. 点击“cell”推出对应的界面

  1.1 新建group,名为:Setting

    路径:MYLottery(我的彩票)->Controller

  1.2 新建Cocoa Touch Class,名为:HMRedeemController

    路径:MYLottery(我的彩票)->Controller->Setting->

       Cocoa Touch Class:(Class:HMRedeemController;Subclass of:UIViewController;Language:Objective-C)

  1.3 在“HMRedeemController.m”的“viewDidLoad”方法中设置“View Controller”的背景为紫色,代码如下:

- (void)viewDidLoad
{
    self.view.backgroundColor = [UIColor purpleColor];
}
View Code

  1.4 在“HMSettingController.m”创建点击“cell”调用方法,代码如下:

//点击 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];
    }    
}
View Code

2. 点击“推送和提醒”推出对应的界面

  2.1 修改“plist”获取方法

    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];
}
View Code

    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;
    }
}
View Code

  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;
View Code

  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
View Code

 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];    //设置子标题颜色
}
View Code

  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];
}
View Code

    5.5.3 在“HMLiveController.m”中创建 toolbar 取消按钮的点击事件,代码如下:

//收键盘
- (void)cancelClick
{
    [self.view endEditing:YES];
}
View Code

    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];
}
View Code