通过数组给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];
}