ios Class类型使用

 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];

 

转载于:https://www.cnblogs.com/PJHome/p/5155643.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值