tableview的两个获得重用cell方法的区别

来源:互联网 发布:java分销系统源码 编辑:程序博客网 时间:2024/05/21 17:12

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]

都可以去缓存池获得可重用的cell,那它们有什么区别呢?


如果你已经用NIB做了一个Cell,或者自定义了一个Cell。我们在你创建UITableView的时候,就可以顺带

[self.tableView registerClass:[CustomCell class] forCellReuseIdentifier:@"CustomCell"];

这样你在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath这个方法里,你就可以省下这些代码:

static NSString *CellIdentifier = @"Cell";if (cell == nil) {                    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];}

而只需要

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];


0 0
原创粉丝点击