1 #import <Foundation/Foundation.h> 2 3 @interface NJProductItem : NSObject 4 /** 5 * 图标 6 */ 7 @property (nonatomic, copy) NSString *icon; 8 /** 9 * 标题 10 */ 11 @property (nonatomic, copy) NSString *tilte; 12 /** 13 * 目标控制器 14 */ 15 @property (nonatomic, assign) Class destVC; 16 17 18 - (instancetype)initWithIcon:(NSString *)icon title:(NSString *)title destClass:(Class)destVc; 19 @end 20 21 22 23 #import "NJProductItem.h" 24 25 @implementation NJProductItem 26 27 - (instancetype)initWithIcon:(NSString *)icon title:(NSString *)title destClass:(Class)destVc 28 { 29 if (self = [super init]) { 30 self.icon = icon; 31 self.tilte = title; 32 self.destVC = destVc ; 33 } 34 35 return self; 36 37 } 38 @end
1 #import <Foundation/Foundation.h> 2 3 @interface NJProductGroup : NSObject 4 /** 5 * 头部标题 6 */ 7 @property (nonatomic, copy) NSString *headerTitle; 8 /** 9 * 底部标题 10 */ 11 @property (nonatomic, copy) NSString *footerTitle; 12 /** 13 * 当前分组中所有行的数据(保存的是NJProductItem模型) 14 */ 15 @property (nonatomic, strong) NSArray *items; 16 17 @end 18 19 #import "NJProductGroup.h" 20 21 @implementation NJProductGroup 22 23 @end
调用
1 if (_datas == nil) { 2 // 第一组数据 3 NJProductItem *item00 = [[NJProductItem alloc] initWithIcon:@"MorePush" title:@"推送和提醒" destClass:[NJTestViewController class]]; 4 NJProductItem *item01 = [[NJProductItem alloc] initWithIcon:@"MorePush" title:@"摇一摇机选" destClass:[NJTestViewController class]]; 5 6 NJProductGroup *group1 = [[NJProductGroup alloc] init]; 7 group1.items = @[item00 ,item01]; 8 9 // 第2组数据 10 NJProductItem *item10 = [[NJProductItem alloc] initWithIcon:@"MorePush" title:@"检查新版本" destClass:[NJTestViewController class]]; 11 NJProductGroup *group2 = [[NJProductGroup alloc] init]; 12 group2.headerTitle = @"第2组的标题"; 13 group2.footerTitle = @"第2组的标题123456"; 14 group2.items = @[item10]; 15 16 _datas = [NSMutableArray array]; 17 [_datas addObject:group1]; 18 [_datas addObject:group2]; 19 20 } 21 return _datas; 22 23 24 25 // 先取出对应组的组模型 26 NJProductGroup *g = self.datas[indexPath.section]; 27 // 从组模型中取出对应行的模型 28 NJProductItem *item = g.items[indexPath.row]; 29 // 创建目标控制并且添加到栈中 30 UIViewController *vc = [[item.destVC alloc] init]; 31 [self.navigationController pushViewController:vc animated:YES];