您的位置:首页 > 其它

给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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: