IOS通过数组给Cell中的文本框和小图标赋值

通过数组给Cell中的文本框和小图标赋值


1、声明一个dataArray数组

@property(nonatomic,strong)  NSMutableArray *dataArray;


2、书写Get方法初始化数组

-(NSMutableArray *)dataArray{


    if (!_dataArray) {

        _dataArray=[NSMutableArray new];

    }

    return _dataArray;

    

}


3、给数组赋值

-(void)initData{

   

NSMutableDictionary *dic1 = [[NSMutableDictionary alloc] init];

    [dic1 setObject:@"邀请好友得大礼包" forKey:@"title"];

    [dic1 setObject:@"giftimg" forKey:@"image"];

    [_dataArray addObject:dic1];

    NSMutableDictionary *dic2 = [[NSMutableDictionary alloc] init];

    [dic2 setObject:@"我的团单" forKey:@"title"];

    [dic2 setObject:@"giftimg" forKey:@"image"];

    [_dataArray addObject:dic2];


}



4、在viewDidLoad中调用数组初始化方法,并调用数组赋值方法


- (void)viewDidLoad {

    [super viewDidLoad];

  

    self.title=@"我的";

    

    //初始化数组

    [self dataArray];


   //给数组赋值,调用赋值方法

    [self initData];

  

}


5、在UITableView的代理方法中对Cell赋值

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


//设置Cell 的可重复利用,减少内存使用

NSString *cellIndentifier = @"mineCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIndentifier];

    }


//给Cell 的标题和图片赋值

  cell.textLabel.text = [_dataArray[indexPath.row] objectForKey:@"title"];

        NSString *imgStr = [_dataArray[indexPath.row] objectForKey:@"image"];

        cell.imageView.image = [UIImage imageNamed:imgStr];


//设置文本的字体颜色和字体大小

 cell.textLabel.textColor=[UIColor darkGrayColor];

  cell.textLabel.font=[UIFont systemFontOfSize:SmallFont];



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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值