我添加了自定义滑动以在 UITableView 中的 UITableViewCells 上共享操作。我的问题是,由于某种原因,它甚至不允许我刷手机。它立即崩溃并显示以下行:
reason: 'attempt to delete row 25 from section 0 which only contains 25 rows before the update'
但是,我并不想删除任何内容!这是分享按钮而不是删除按钮。以下是我添加的相关方法:
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let shareAction = UITableViewRowAction(style: .Normal, title: "Share") { (action: UITableViewRowAction, indexPath: NSIndexPath) -> Void in
// Some stuff
}
shareAction.backgroundColor = UIColor.yellowColor()
return [shareAction]
}
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
}
当我的 TableView Controller 不应该尝试删除任何内容时,为什么会出现此错误?
最佳答案
事实证明这是一个与上述三种方法无关的问题。我的 TableView Controller 是一个 PFQueryTableViewController 子类,它具有开箱即用的 numberOfRowsInSection
。我的问题是我在不应该添加的时候明确添加了该方法。因此,它在不应该的时候被调用(它隐式构建到子类中),导致一些不稳定的行为。我删除了对 numberOfRowsInSection
的调用,它按预期工作。
关于ios - UITableViewCell 上的自定义编辑操作因尝试删除而在滑动时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34260513/