我试图让我的tableView选择的行数:直到选择一些如何在Swift中对选定的UITableView行进行计数。可选的indexPathForSelectedRow
self.tableView.setEditing(true, animated: true)
tableView.allowsMultipleSelection = true
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
updateCount()
}
func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
updateCount()
}
func updateCount(){
let list = tableView.indexPathsForSelectedRows() as [NSIndexPath]
println(list.count)
一切工作良好。但是,当没有选择列,应用程序崩溃“致命错误:意外发现零而展开的可选值”。 我想这是因为选择是零,但如何写代码选配?我试过 很多方法,但是当我取消所有选择的应用程序仍然崩溃。
但为什么你要这么做? – 2014-12-05 07:09:16
例如,我可以有一个按钮,“删除”显示要删除的项目数。 – migari 2014-12-05 20:59:51