产生此问题是因为您的UITableView
Reuse Cell 即时创建新的。我给你一些建议,可能对你有帮助。
1)UIView
在两者之间添加
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
/// Your code;
}
return cell;
}
1)将您的 UIView 添加到cell.contentView.
编辑:
在您遵循我的编辑答案之前,我想告诉您以下代码对内存管理不利,因为它会为 的每一行创建新单元格UITableView
,因此请小心。
但是如果UITableView
有限制行(可能是 50-100 行),如果它适合您,则使用以下代码会更好。
NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell == nil)
{
}