IOS通过数组给Cell中的文本框和小图标赋值
2015-11-21 18:36
369 查看
通过数组给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];
}
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];
}
相关文章推荐
- iOS开发中同时识别旋转与缩放手势
- iOS命名规范
- iOS 时间格式 时间转换 大总结
- iOS 9 适配系列教程
- ios 轻量级 数据的缓存
- iOS 无法解析 报错std::basic_string/std::string::find
- iOS 8星空背景
- 中文 iOS/Mac 开发博客列表
- 提升iOS开发效率的必用工具
- iOS蓝牙4.0开发例子
- iOS AutoLayout 百分比布局
- 关于iOS modal界面跳转黑屏的原因及解决方案
- iOS中,byte[] 转成NSString
- iOS开发中常用的开源框架
- 项目回顾(iOS远程推送)
- iOS 判断名字、省份证号、电话号码、邮箱 、车牌号码的正则表达式
- ios coredata 无任何错误提示crash
- iOS 本地数据持久化
- iOS崩溃信息符号化
- [转载]iOS_多线程GCD