美文网首页
加载nib形式的Cell解决重用问题

加载nib形式的Cell解决重用问题

作者: 童宁_深圳_iOS | 来源:发表于2017-04-17 15:18 被阅读0次

当一个tableview加载不同的cell,且cell是xib类型时,需要以下方法,解决重用cell报错问题:

```

static NSString *CellIdentifier = @"Cell";

BOOL nibsRegistered = NO;

if ( !nibsRegistered ) {

UINib *nib = [UINib nibWithNibName:NSStringFromClass([Cell class]) bundle:nil];

[tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];

nibsRegistered=YES;

}

Cell*cell = (Cell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

cell.titleLabel.text=[self.dataList objectAtIndex:indexPath.row];

return cell;

```

相关文章

网友评论

      本文标题:加载nib形式的Cell解决重用问题

      本文链接:https://www.haomeiwen.com/subject/ecptzttx.html