1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| #import "ILSettingTableViewController.h" #import "ILSettingItem.h" #import "ILSettingGroup.h" #import "ILSettingCell.h" #import "ILSettingArrowItem.h" #import "ILSettingSwitchItem.h" #import "ILTestViewController.h"
@interface ILSettingTableViewController ()
@property (nonatomic,strong) NSMutableArray *dataList;
@end
@implementation ILSettingTableViewController
-(NSMutableArray *)dataList { if(_dataList==nil) { _dataList=[NSMutableArray array]; //第0组 ILSettingArrowItem *pushNotice=[ILSettingArrowItem itemWithIcon:@"MorePush" title:@"推送和提醒"]; pushNotice.destVcClass=[ILTestViewController class]; pushNotice.destVcName=@"ILTestViewController"; ILSettingItem *yaoyiyao=[ILSettingSwitchItem itemWithIcon:@"handShake" title:@"摇一摇机选"]; ILSettingItem *vioce=[ILSettingSwitchItem itemWithIcon:@"sound_Effect" title:@"声音效果"]; //NSArray *group0=@[pushNotice,yaoyiyao]; ILSettingGroup *group0=[[ILSettingGroup alloc]init]; group0.items=@[pushNotice,yaoyiyao,vioce]; group0.header=@"标题头部-1"; group0.footer=@"标题尾部-1"; //第1组 ILSettingItem *newVersion=[ILSettingArrowItem itemWithIcon:@"MoreUpdate" title:@"检测新版本"]; ILSettingItem *help=[ILSettingArrowItem itemWithIcon:@"MoreHelp" title:@"帮助"]; ILSettingItem *share=[ILSettingArrowItem itemWithIcon:@"MoreShare" title:@"分享"]; ILSettingItem *message=[ILSettingArrowItem itemWithIcon:@"MoreMessage" title:@"查看消息"]; ILSettingItem *recommend=[ILSettingArrowItem itemWithIcon:@"MoreNetease" title:@"产品推荐"]; ILSettingItem *about=[ILSettingArrowItem itemWithIcon:@"MoreAbout" title:@"关于"]; //NSArray *group1=@[newVersion,help]; ILSettingGroup *group1=[[ILSettingGroup alloc]init]; group1.items=@[newVersion,help,share,message,recommend,about]; group1.header=@"标题头部-2"; group1.footer=@"标题尾部-2"; [_dataList addObject:group0]; [_dataList addObject:group1]; } return _dataList; }
- (instancetype)init { return [super initWithStyle:UITableViewStyleGrouped]; } - (void)viewDidLoad { [super viewDidLoad]; //self.tableView.rowHeight=200; // Uncomment the following line to preserve selection between presentations. // self.clearsSelectionOnViewWillAppear = NO; // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem; }
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { #warning Incomplete implementation, return the number of sections return self.dataList.count; }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { #warning Incomplete implementation, return the number of rows //NSArray *arr=self.dataList[section]; ILSettingGroup *group=self.dataList[section]; return group.items.count; }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // static NSString *ID=@"cell"; // UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; // if (cell==nil) { // cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID]; // } //1-创建cell ILSettingCell *cell=[[ILSettingCell class] cellWithTableView:tableView]; //2-取出模型 ILSettingGroup *group=self.dataList[indexPath.section]; //ILSettingItem *item=self.dataList[indexPath.section][indexPath.row]; ILSettingItem *item=group.items[indexPath.row];
//cell.imageView.image=[UIImage imageNamed:item.icon]; //cell.textLabel.text=item.title; //传递模型 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; } -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { //取出模型 ILSettingGroup *group=self.dataList[indexPath.section]; //ILSettingItem *item=self.dataList[indexPath.section][indexPath.row]; ILSettingItem *item=group.items[indexPath.row]; //创建跳转的控制器 if([item isKindOfClass:[ILSettingArrowItem class]]) { ILSettingArrowItem *arrowItem=(ILSettingArrowItem *)item; Class vcClass=NSClassFromString(arrowItem.destVcName); UIViewController *vc=[[vcClass alloc]init]; //UIViewController *vc=[arrowItem.destVcClass alloc]; [self.navigationController pushViewController:vc animated:YES]; } }
@end
|