ios - 尝试删除表行时出错 : UITableView internal bug

标签 ios swift uitableview

我使用的方法是用户可以选择删除除其他对象之外的对象。当我单击“删除”时,出现以下错误:

原因:'UITableView内部错误:无法生成旧部分计数:1和新部分计数:0的新部分图'

这是我的代码:

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {

        let position = UITableViewRowAction(style: UITableViewRowActionStyle.Normal, title: "Posição", handler: { (action: UITableViewRowAction, indexPath: NSIndexPath) -> Void in
            tableView.editing = false
        })

        let remove = UITableViewRowAction(style: UITableViewRowActionStyle.Destructive, title: "Remover", handler: { (action: UITableViewRowAction, indexPath: NSIndexPath) -> Void in
            self.tableData.removeObjectAtIndex(indexPath.row)
            tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
        })

        return [remove, position]
    }

我确实需要使用 editActionsForRowAtIndexPath 方法

最佳答案

您需要先从表数据源中删除该对象。

试试这个

tableView.beginUpdates()
self.tableData.removeObjectAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
tableView.endUpdates()

关于ios - 尝试删除表行时出错 : UITableView internal bug,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33306591/

相关文章:

ios - 如何在 UITableViewCell 之间添加间距

ios - 如何通过生成 pdf 的缩略图来预加载 CollectionView 中的图像?

ios - AudioQueueNewOutput 与 AudioQueueRef?总是展开 nil

ios - 此iPad应用程序崩溃日志引用哪个线程?

iphone - 带有关闭 block 的 presentViewController

swift - 为什么我在迭代场景中的每个节点时都会收到 EXC_BREAKPOINT?

iphone - 从字典中的数组中删除与搜索词匹配的所有值(字符串)?

ios - 为什么我不能在我的 objective-c 代码中使用我的 swift 文件?

swift - 解析 mLabs 和 Heroku 的迁移错误

ios - 如何为自动调整单元格正确设置自动布局约束