ios - UITableViewCell 上的自定义编辑操作因尝试删除而在滑动时崩溃

标签 ios swift uitableview delegates

我添加了自定义滑动以在 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/

相关文章:

ios - 链接 SceneKit Framework 避免在 iOS 7 上崩溃

ios - 在继续之前等待 NSNotification

ios - 如何在 XIB 或不包含 Storyboard的项目中使用 map ?

swift - 在 Swift 中获取今天和给定日期之间的日期数组?

ios - 使用 Swift 在 Xcode 6 中使用 xib 在自定义 uiview 中获取 SIGABRT

ios - Swift:关闭 ImageView

ios - 我正在尝试按位置对用户的帖子进行排序并使用 PFGeopoint 和 Swift 显示距离

ios - 在 TableView 上显示具有特殊字符的联系人时遇到问题

ios - 在 iOS 的 tableview 中动态搜索

ios - 使用 didSet 进行通知时出现问题