iphone - 如何跟踪 UITableView 中所有选定单元格的索引

标签 iphone

我有一个大约 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,它可以添加与所选单元格相对应的 nNSIndexPath。当取消选择某个单元格时,您可以从数组中删除该索引路径。

关于iphone - 如何跟踪 UITableView 中所有选定单元格的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8252363/

相关文章:

ios - 当 UITableViewCell 处于编辑模式并且我们重新加载 UITableView 时,即使在重新加载后如何保持该特定单元格处于编辑模式

ios - LaunchScreen.storyboard 如何重定向到 Main.storyboard

iphone - 在 iphone 中单击按钮时弹出 View 显示字符串

ios - 如何加速核心数据迁移或其他解决方案

iphone - UIView 的 drawRect 没有被调用

iphone - 循环遍历 UITableView 的 UITableViewCells

ios - 离开屏幕时保持对象状态

ios - 如何设置AppStore支持的最高iOS版本

iphone - iPhone 上 UISlider 的弹性效果

ios - 尺寸等级的约束在哪里更新?