我对重用 UITableViewCell 有点怀疑。
当我们创建 UITableViewCell 时,它看起来像下面这样。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
[self configureCell:cell forIndexPath:indexPath];
}
}
- (void)configureCell:(UITableViewCell *)cell forIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.section) {/**Cell Config Code Goes Here**/}
}
所以在我的例子中,UITableView 中的每个单元格都是不同的。如果 UITableView 重用单元格,则单元格内容完全不同。
将 CellIdentifier 传递为 nil 是否是一种好习惯,以便每次创建新单元时,而不是在所有单元都不同的条件下?
或者我应该只是移动 [self configureCell:cell forIndexPath:indexPath]; 出来自己处理?