所以我创建了一个如下所示的 TableView,但我遇到了一个非常烦人的问题。
来到这个VC,点击Choose User,我选择了用户Atoshum。
当我向下滚动时,当我滚动底部单元格时,这个顶部单元格会离开屏幕。
当我向上滚动时,单元格已恢复为默认值(或偶尔采用另一个单元格的值)。
我这样制作细胞。
static NSString *CellIdentifier = @"Cell";
DMSDrugInstanceCell *Cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!Cell) {
Cell = [[DMSDrugInstanceCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
Cell.chooseUserButton.tag = indexPath.row;
[Cell.chooseUserButton addTarget:self
action:@selector(performSegue:)
forControlEvents:UIControlEventTouchUpInside];
return Cell;
最佳答案
在创建单元格时,您永远不会设置任何值。您所做的就是设置标签,然后添加一个事件目标。如果您希望它保留选择,则需要在做出选择时存储/保存该选择,然后在创建的单元格中,根据保存的值进行设置。
关于ios - UITableViewCells 恢复为默认值或其他值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20547865/