ios - UITableView 多选和滑动操作

标签 ios uitableview

我有一个启用了多选的 UITableView。我一直在使用“选择”来实际更改行的高度,在“选择”时显示额外的细节。例如

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.tableView.beginUpdates()
    self.tableView.endUpdates()
}

func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
    self.tableView.beginUpdates()
    self.tableView.endUpdates()
}

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return (self.tableView.indexPathsForSelectedRows?.contains(indexPath) ?? false) ? 200 : 92
}

这似乎工作得很好。直到我开始做任何滑动 Action 。当我添加一些滑动 Action 时,滑动 Action 似乎清除了我所有的选择。我实际上想取消选择我正在滑动的那个,所以它会缩小。但是清除我所有的选择似乎并没有触发任何正常的委托(delegate)回调。即使我将 allowsMultipleSelectionDuringEditing 设置为 true。

有没有办法做到这一点?我是否应该跳过(ab)使用选择状态来指示该行是否显示具有不同高度的详细信息?或者有没有办法将它与在“编辑模式”下完成的滑动行为结合使用并清除我的所有选择?

最佳答案

最好的方法是使用 NSArray 存储选定单元格的索引路径,并根据保存的索引路径您可以检查并执行任何您想要的操作。您的代码中可能发生的另一个错误是:用户在 tableview 上滚动的情况下发生了什么?单元格会重用并丢失选择状态吗?新cell重用200高度的旧cell会出现高度错误吗?

关于ios - UITableView 多选和滑动操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37738171/

相关文章:

ios - 设置背景图像时 UILabel 不显示文本

ios - UITableview 自动调整行问题 Swift IOS?

ios - Cross Directional UIScrollViews - 我可以修改滚动行为吗?

ios - 在自定义 UITableViewHeaderFooterView 上添加一个按钮

iOS:将 OpenAL 的变调和管道输出输出到缓冲区

iphone - NSFetchRequest 以特定顺序显示结果

iphone - iOS CoreImage 边缘检测

ios - 使用图像和标签设置 Tableview 背景

ios - 我需要在页面控件内的 tableView 上检测滑动手势,我该怎么做?

ios - 如何在 iOS 11 中支持大标签栏预览?