【发布时间】:2016-07-08 12:51:07
【问题描述】:
我正在制作一个需要用户点击多个单元格才能选择它们的应用程序。当他们点击一个单元格时,会出现一个 .Checkmark 附件项目。出于某种原因,尽管每当我尝试访问该 VC 时,应用程序都会崩溃,并且我在第 8 行收到以下错误消息(如果!checked[indexPath.row]):
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell: InstrumentTableCell! = tableView.dequeueReusableCellWithIdentifier(identifier) as? InstrumentTableCell
cell.configurateTheCell(recipies[indexPath.row])
if !checked[indexPath.row] {
cell.accessoryType = .None
} else if checked[indexPath.row] {
cell.accessoryType = .Checkmark
}
return cell
}
这是我的工作检查方法:
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
{
tableView.deselectRowAtIndexPath(indexPath, animated: true)
if let cell = tableView.cellForRowAtIndexPath(indexPath) {
if cell.accessoryType == .Checkmark {
cell.accessoryType = .None
checked[indexPath.row] = false
} else {
cell.accessoryType = .Checkmark
checked[indexPath.row] = true
}
}
}
【问题讨论】:
-
好的,你的
checked方法是什么样的? -
pbodsk 我更新了问题以添加选中的方法:)
-
啊...好的,所以
checked是一个数组,您可以在其中存储是否检查了一行,对吗? -
是的,检查商店是否检查了一行
-
它看起来像
checked.count == 0或checked == nil在你做if !checked[indexPath.row]的那一刻
标签: swift uitableview swift2 nsindexpath exc-bad-instruction