自定义Cell(完成设置界面)并且自定义一个基类控制器(ZZSettingViewController)(自定义Cell4⃣️)

来源:互联网 发布:服装批发软件手机版 编辑:程序博客网 时间:2024/06/06 15:50

//

//  ZZSettingViewController.h

//  ZZ_APP主流框架

//

//  Created by ZZ_Macpro on 15/10/9.

//  Copyright (c) 2015 ZZ_Macpro. All rights reserved.

//


#import <UIKit/UIKit.h>

@class ZZSettingGroup;


@interface ZZSettingViewController :UITableViewController

@property (nonatomic,strong) NSMutableArray *groups;


- (ZZSettingGroup *)addGroup;

@end


//

//  ZZSettingViewController.m

//  ZZ_APP主流框架

//

//  Created by ZZ_Macpro on 15/10/9.

//  Copyright (c) 2015 ZZ_Macpro. All rights reserved.

//


#import "ZZSettingViewController.h"

#import "ZZSettingGroup.h"

#import "ZZSettingCell.h"

#import "ZZSettingArrowItem.h"

#import "ZZSettingCheckItem.h"

#import "ZZSettingCheckGroup.h"


#define ZZCellMargin 6


@interface ZZSettingViewController ()


@end


@implementation ZZSettingViewController


- (NSMutableArray *)groups

{

   if (_groups ==nil) {

       _groups = [NSMutableArrayarray];

    }

    return_groups;

}


- (ZZSettingGroup *)addGroup

{

    ZZSettingGroup *group = [ZZSettingGroupgroup];

    [self.groupsaddObject:group];

   return group;

}


- (id)initWithStyle:(UITableViewStyle)style

{

    return [superinitWithStyle:UITableViewStyleGrouped];

}


- (id)init

{

    return [superinitWithStyle:UITableViewStyleGrouped];

}


- (void)viewDidAppear:(BOOL)animated

{

    [superviewDidAppear:animated];

}


- (void)viewDidLoad

{

    [superviewDidLoad];

    

    self.tableView.separatorStyle =UITableViewCellSelectionStyleNone;

    self.tableView.backgroundView =nil;

    self.view.backgroundColor =ZZGlobalBg;

    

    self.tableView.sectionHeaderHeight =0; //每一组的头部高度

    self.tableView.sectionFooterHeight =ZZCellMargin;// 每一组的尾部高度

    

    // 底部控件

   UIView *footer = [[UIViewalloc] init];

    footer.frame =CGRectMake(0,0, 0,1);

    self.tableView.tableFooterView = footer;

    

   if (iOS7) {

        self.tableView.contentInset =UIEdgeInsetsMake(ZZCellMargin -33, 0, 0,0);

    }else {

        self.tableView.contentInset =UIEdgeInsetsMake(ZZCellMargin,0, 0,0);

    }

}


#pragma mark ------  Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    returnself.groups.count;

}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

   ZZSettingGroup *group = self.groups[section];

   return group.items.count;

}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

   ZZSettingCell *cell = [ZZSettingCellcellWithTableView:tableView];

    cell.indexPath = indexPath;

    

   ZZSettingGroup *group = self.groups[indexPath.section];

    cell.item = group.items[indexPath.row];

   return cell;

}


#pragma mark ------ 代理

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

{

   ZZSettingGroup *group = self.groups[section];

   return group.footer;

}


- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

   ZZSettingGroup *group = self.groups[section];

   return group.header;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    [tableView deselectRowAtIndexPath:indexPathanimated:YES];

    

    // 0.取出模型

   ZZSettingGroup *group = self.groups[indexPath.section];

   ZZSettingItem *item = group.items[indexPath.row];

    

    // 1.操作

   if (item.option) {

        item.option();

    }

    

    // 2.跳转

   if ([item isKindOfClass:[ZZSettingArrowItemclass]]) {

        ZZSettingArrowItem *arrowItem = (ZZSettingArrowItem *)item;

        

       if (arrowItem.destVcClass) {

           UIViewController *destVc = [[arrowItem.destVcClassalloc] init];

            destVc.title = arrowItem.title;

            

           if (arrowItem.readyForDestVc) {// 控制器的准备工作

                arrowItem.readyForDestVc(arrowItem, destVc);

            }

            

            [self.navigationControllerpushViewController:destVc animated:YES];

        }

    }

    

    // 3.check 打勾

   if ([item isKindOfClass:[ZZSettingCheckItemclass]]) {

        ZZSettingCheckGroup *checkGroup = (ZZSettingCheckGroup *)group;

        checkGroup.checkedIndex = indexPath.row;

        

       // 刷新

        [tableViewreloadData];

    }

}

@end



1 0