我有一个大约 20 行的 UITableView
。我还使用复选标记配件来识别所选内容。我现在面临的问题是,当我滚动时,选择会变得困惑(这里我选择多行)。因此,滚动后所选的复选标记
消失了。谁能帮我找到方法吗?在didSelectRowAtIndexPath:
NSMutableDictionary *rowDict = [tableList objectAtIndex:[indexPath row]];
if([tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark)
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
}
else
{
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
checkedIndexPath = indexPath;
NSLog(@"the checked psths are :%@",checkedIndexPath);
}
在cellforrowatIndexpath
中我使用
if([self.checkedIndexPath isEqual:indexPath])
{
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
}
但这仅适用于单选。多重选择应该怎么做?
最佳答案
您可以拥有一个 NSMutableArray
,它可以添加与所选单元格相对应的 n
个 NSIndexPath
。当取消选择某个单元格时,您可以从数组中删除该索引路径。
关于iphone - 如何跟踪 UITableView 中所有选定单元格的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8252363/