更新时间:2023-11-01 08:25:34
UITableViewCells被重新使用以优化性能。这发生在 [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
您需要在每次调用 tableView:(UITableView时,在单元格上显式设置您想要的任何属性*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
。
UITableViewCells are reused to optimize performance. This happens in [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
You need to explicitly set any properties you would like on the cell at each call of tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
.
类似这样的方法可以解决问题:
Something like this should resolve the issue:
if (indexPath.row == 5 || indexPath.row == 7)
{
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else
{
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryNone;
}