这让我发疯了,我已经查看了所有与此相关的帖子。
我正在使用自定义表格 View 单元格类和 XIB 文件。一切正常,直到我将表格 View 滚动到屏幕外(那个老栗子)。我知道它与 dequeueReusableCellWithIdentifier 方法有关,而不是清除旧数据。但是我不知道如何实现这个。
一旦单元格滚出屏幕,它会导致重叠并继续向单元格添加图像。
let cell: DetailHeaderTableViewCell = tableView.dequeueReusableCellWithIdentifier("detailHeaderTableViewCell") as DetailHeaderTableViewCell
根据我的发现,我需要实现如下内容:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
UIImageView *defaultImageView;
UILabel *customLabel;
if (cell == nil) {
// create the cell and empty views ready to take the content.
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
} else { ... }
但是我不知道如何快速实现这一目标。
非常感谢。
最佳答案
您要找的是UITableViewCell's prepareForReuse
方法。
如果您使用的是自定义 UITableView 单元格,则需要实现此方法以在重新使用单元格之前清除单元格中的所有旧数据。
关于iOS Swift dequeueReusableCellWithIdentifier 导致重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27245322/