【发布时间】:2016-01-26 09:29:04
【问题描述】:
我有一个空数组:
var indexPathArray: [[NSIndexPath]] = [[]]
我有一个在多个部分中包含多行的 tableView。 当在 UITableView 中按下一个单元格时,它会将 NSIndexPath 添加到数组中,如下所示:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
indexPathArray[indexPath.section].append(indexPath)
}
如果第 1 节第一行的单元格被选中,前面的方法会将 NSIndexPath 添加到 indexPathArray 的第一个数组中。结果将如下所示:
[ [indexPath], [],[] ]
当我取消选择单元格时,我想过滤掉我选择的内容。我实现了以下:
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
indexPathArray = indexPathArray[indexPath.section].filter({ $0 != indexPath })
}
在 indexPathArray 中的每个数组中,如果取消选择相同的 indexPath 项,我基本上会尝试取出。例如,如果我双击一个单元格两次,indexPath 项将被添加并被过滤功能删除。
但是,它在过滤器函数上抛出一个错误:
Cannot invoke 'filter' with an argument list of type '(@noescape (NSIndexPath) throws -> Bool)'
expected an argument list of type (@noescape (Self.Generator.Element) throws -> Bool)
我在这里做错了什么?
【问题讨论】:
-
你为什么不用
-indexPathsForSelectedRows
标签: ios arrays swift uitableview nsindexpath