1. 新建Cocoa Touch Class:

  MYLottery(我的彩票)->Controller->Class:HMSetingController;Subclass of:UITableViewController

  在“HMSetingController.m”的“viewDidLoad”方法中设置标题和返回按钮,创建返回按钮的点击事件方法,代码如下:

- (void)viewDidLoad
{
    //设置标题
    self.navigationItem.title = @"设置"//创建返回按钮
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"NavBack"] style:UIBarButtonItemStylePlain
    targer:self action:@selector(backClick)];
    //设置 leftbaritem
    self.navigationItem.leftBarButtonItem = item;
}
//点击返回按钮事件
- (void)backClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
View Code

2. “设置”按钮基本页面

  ”设置“按钮->拖线->HMMyLotteryController.m:implementation->代码如下:

- (IBAction)settingClick:(id)sender 
{
    //跳转到设置页面(组类型TableView)
    HMSettingController *setting = [[HMSettingController alloc] initWithStyle:UITableViewStyleGrouped];

    [self.navigationContrller pushViewControll:setting animated:YES];
}
View Code

3. 创建plist数据

  3.1 新建Property List

    Classes->MYLottery(我的彩票)->Other->(Save As:Setting.plist;Tags:空)

    格式如下:

Root:Array
    Item 0:Dictionary
        Items:Array
            Item0:Dictionary
                targetVC:String 要跳转到的View Controller的名字
                accessoryContent:String arrow_right
                accessoryType:String UIImageView
                title:String
                icon:String
            footer
            header
View Code

4. plist懒加载设置界面的cell

  4.1 HMSettingController.m:interface->申明变量:@property (nonatomic, strong) NSArray *groups

  4.2 HMMyLotteryController.m:implementation->懒加载,代码如下:

- (NSArray *)groups {
    if (!_groups) {
        //获取路径
        NSString *path = [[NSBundle mainBundle] pathForResource:@"Setting" ofType:@"plist"];

        //解析成数组
        _groups = [NSArray arrayWithContentsOfFile:path];
    }
    return _groups;        
}
View Code

5 在“HMMyLotteryController.m”新建数据源方法,代码如下:

//有多少组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.groups.count;
}
//每1组有多少行
- (NSInteger)tableView:(UITableView)tableView numberOfRowsInSection:(NSInteger)section
{
    //获取组
    NSDictionary *group = self.groups[section];
    //获取当前组所有的cell信息
    NSArray * items = group[@"items"];
    return items.count;
}
View Code

6. 在“HMMyLotteryController.m”新建cell长什么样方法,代码如下:

//cell长什么样
- (UITableViewCell *)tableView:(UITableViw *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //获取当前cell的信息
    //1.获取组
    NSDictionary *group = self.groups[indexPath.section];
    //2.获取当前组的所有的cell信息
    NSArray *items = group[@"items"];
    //3.当前cell的信息
    NSDictionary *item = items[indexPath.row];

    static NSString *cellid = @"setting_cell";

    //缓存池找
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];

    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
    }
    
    //赋值
    cell.imageView.image = [UIImage imageNamed:item[@"icon"]];
    cell.textLable.text = item[@"title"];

    //根据字符生成对象
    //获取accessoryType的字符串
    NSString *accessoryType = item[@"accessoryType"];    
    //将字符串转换成类
    Class Clz = NSClassFromString(accessoryType);
    //获取accessoryType的对象
    UIView *obj = [[Clz alloc] init];
    
    //判断obj真实的类型
    if ([obj isKingOfClass:[UIImageView class]]) {
        //设置frame,强转为图片类型
        UIImageView *imageView = (UIImageView *)obj;
        imageView.image = [UIImage imageName:item[@"accessoryContent"];
        [imageView sizeToFist];
    }
    cell.accessoryView = obj;

    return cell;
}
View Code

7. 点击cell推出对应的界面

  7.1 新建Cocoa Touch Class

    Classes->MYLottery(我的彩票)->Controller->Setting->(Class:HMRedeemController;Subclass of:UIViewController;Language:Objective-C)

  7.2 在“HMRedeemController”的“viewDidLoad”中创建背景为紫色的View Controller,代码如下:

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

  7.3 HMSettingController.m:implementation->代码如下:

//点击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) {
        //@"HMRedeemController"
        NSString *targetVC = item[@"targetVC"];
        //HMRedeemController
        Class Clz = NSClassFromString(targetVC);
        //HMRedeemController类型的对象
        UIViewController *vc = [[Clz alloc] init];
        vc.navigationItem.title = item[@"title"];
        //跳转
        [self.navigationController pushViewController:vc animated:YES];
    }
}
View Code

 

7. 在“HMMyLotteryController.m”新建获取header信息的方法,代码如下:
//获取 header 信息
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
//获取需要展示 header 的组
NSDictionary *group = self.groups[section];

return group[@"header"];
}
8. 在“HMMyLotteryController.m”新建获取footer信息的方法,代码如下:
//获取 footer 信息
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
//获取需要展示 footer 的组
NSDictionary *group = self.groups[section];

return group[@"footer"];

8. 点击“使用兑换码”cell推出对应的界面

  8.1 新建文件夹Setting,

新建Cocoa Touch Class

    Classes->MYLottery(我的彩票)->Controller->Setting->(Class:HMRedeemController;Subclass of:UIViewController;Language:Objective-C)

  8.2 在“HMRedeemController”的“viewDidLoad”中创建背景为紫色的View Controller,代码如下: