控制器与cell之间传数据

控制器与cell之间传数据

【一般 在控制器中 请求 网络数据】
1、在控制器中 定义 模型数组 (包含多个模型数据)  

@property(strong,nonatomic)NSMutableArray *couponItems;  

在控制器中实现 get方法

-(NSMutableArray *)couponItems{

    if(_couponItems==nil){

        _couponItems=[NSMutableArray array];

// 请求网络数据 

        for(int i=0;i<4;i++){

            HJCouponItem *item=[[HJCouponItem alloc]init];

            item.date = @"Valid date:Jun 17 2015";

            item.discount = @"15%OFF";

            item.discribe = @"15%of with app order“;

            item.code = @"Code:fabfb8";

            [_couponItems addObject:item];

        }

    }

    return _couponItems;

}

2、在cell 的头文件中  定义一个 模型变量  

@property(strong,nonatomic)HJCouponItem *couponItem;

3、在控制器的cell处,赋值给cell的模型变量  

    cell.couponItem = self.couponItems[indexPath.row];

4、在cell的实现 文件中  实现模型的set方法 ,用来传值 

-(void)setCouponItem:(HJCouponItem *)couponItem

{

    _couponItem = couponItem;

    self.offlbl.text = couponItem.discount;

    self.date.text = couponItem.date;

    self.discoun.text = couponItem.discribe;

    self.code.text = couponItem.code;

}

5、如果cell中的子控件需要用到 模型数据时 必须要将 子控件赋值给 cell申明的控件变量  

@property (weak,nonatomic)UILabel  *offlbl;      self.offlbl = offlbl;

@property (weak,nonatomic)UILabel  *code;      self.code = code;

6、cell子控件的 布局必须在 layout中实现 ;

-(void)layoutSubviews{

    [super layoutSubviews];

    

    CGFloat padding = 10;

    CGFloat lblpadding = 14;

。。。。。。

    self.imgLine.frame = CGRectMake(CGRectGetMaxX(self.discoun.frame), 0, 7, 87);

}

7、layout 中的屏幕宽度 使用 self.view.frame.size.width; 不能使用ScreenWidth 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值