给tableView 的cell赋值的几种写法
2015-12-01 19:20
381 查看
方法一:
//防止写错
NSString *cellID = @"远";
//1.检查重用池中是否有cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
//2.判断获取的cell是否为空
if (cell == nil) {
//若果cell为空,说明重用池中没有cell,需要我们重新创建一个
cell =
[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID]autorelease];
NSLog(@"创建一个");
}
//3.重新给cell赋值
NSString *name = [self.sourceArr objectAtIndex:indexPath.row];
cell.textLabel.text = name;
//cell.textLabel.text = @"真帅";
return cell;
方法二:
//注册
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
//在cell赋值的方法里面写
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
//在这块赋值
return cell;
方法三:
static NSString *CellIdentifier = @"reuse2";
BOOL nibsRegistered = NO;
if (!nibsRegistered) {
UINib *nib = [UINib nibWithNibName:NSStringFromClass([LPWorkDayTwoTableViewCell class]) bundle:nil];
[tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];
}
LPWorkDayTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse2"];
//在这块赋值
return cell;
//防止写错
NSString *cellID = @"远";
//1.检查重用池中是否有cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
//2.判断获取的cell是否为空
if (cell == nil) {
//若果cell为空,说明重用池中没有cell,需要我们重新创建一个
cell =
[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID]autorelease];
NSLog(@"创建一个");
}
//3.重新给cell赋值
NSString *name = [self.sourceArr objectAtIndex:indexPath.row];
cell.textLabel.text = name;
//cell.textLabel.text = @"真帅";
return cell;
方法二:
//注册
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse"];
//在cell赋值的方法里面写
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
//在这块赋值
return cell;
方法三:
static NSString *CellIdentifier = @"reuse2";
BOOL nibsRegistered = NO;
if (!nibsRegistered) {
UINib *nib = [UINib nibWithNibName:NSStringFromClass([LPWorkDayTwoTableViewCell class]) bundle:nil];
[tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];
}
LPWorkDayTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse2"];
//在这块赋值
return cell;
相关文章推荐
- 抽象类第一课(代码)
- CCF软考---《有趣的数》
- [LeetCode]Recover Binary Search Tree
- LeetCode 58 : Length of Last Word (Java)
- 求解,windows编程中,win32程序,如何将字符串按一个一个字符逐个动态输出?
- UltraEdit高级技巧集锦
- XML数据解析的两种方法:SAX和DOM
- C++基础
- 数据结构-- 向量--插值查找
- Java 关键字
- 浅谈WebService的调用<转>
- 深入浅出三剑客之awk必杀技一例 【转】
- 1019. General Palindromic Number (20)——PAT (Advanced Level) Practise
- SSH 整合常见的错误
- 如何配置pl/sql 连接远程oracle服务器
- 4.10 练习
- 切换视图控制器时将标签栏隐藏
- 网址之Curl API整理说明
- jquery.autocomplete自动补全功能
- iptables防火墙