我创建了一个表格视图并显示了数据。当我单击表格视图中的数据时,我放置了附件标记(使用 UITableViewCellAccessoryCheckmark、Like、Check Mark)。现在我想保留索引位置的状态。因为当我去另一个班级然后回到表格视图时,会显示以前的状态(附件标记)。那么我怎样才能保留状态,这意味着存储或保存 indexpath 值。(不使用 AppDelegate 方法)那么我该如何实现呢?
这是我的示例代码,
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (newRow != oldRow)
{
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:
indexPath];
newCell.accessoryType = UITableViewCellAccessoryCheckmark;
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:
checkedData];
oldCell.accessoryType = UITableViewCellAccessoryNone;
checkedData = indexPath;
}
if (newRow == oldRow) {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryNone) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
// cell.accessoryType = UITableViewCellAccessoryNone;
}
checkedData = indexPath;
}
}
当返回表视图类时,应该保留之前的状态。那么我该如何访问呢?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(checkedData == indexPath) // Doesn't works
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
请帮帮我。
谢谢