尝试删除时SwipeCellKit崩溃

时间:2017-06-14 10:52:28

标签: ios uitableview swift3

您好我的UITableView使用了SwipeCellKit。我想在刷细胞时进行删除。这就是我处理删除部分的方法。 self.deleteLeave()正在调用Web服务并删除服务器端的所选离开条目。然后,如果它在服务器端成功删除,我想从当前数组中删除该对象并更新我的UITableView。但我的问题是当我滑动并单击删除按钮或拖动它在某种程度上应用程序崩溃通过给出异常。

错误

  

由于未捕获的异常而终止应用   ' NSInternalInconsistencyException',原因:'无效更新:无效   第0节中的行数。包含在中的行数   更新后的现有部分(1)必须等于数量   在更新(1)之前,该部分中包含的行加或减   从该部分插入或删除的行数(插入0,   删除1)加上或减去移入或移出的行数   该部分(0移入,0移出)。'

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? {
    guard orientation == .right else { return nil }

    let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in
        // handle action by updating model with deletion
        self.com.showProgress()
        let dict=self.arrayPendings[indexPath.row] as! [String:Any]
        if let reid=dict["RequestId"] as? Int
        {
            self.selectedReqID=String(reid)
        }
        self.deleteLeave(){ (status) in

            if(status)
            {

                let delete = SwipeAction(style: .destructive, title: nil) { action, indexPath in

                    self.com.removeProgress()
                     self.arrayPendings.remove(at: indexPath.row)
                   self.tblPendingLeaves.beginUpdates()
                    //self.tblPendingLeaves.insertRows(at: [IndexPath(row: 0, section: 1)], with: .automatic)
                    self.tblPendingLeaves.deleteRows(at: [indexPath], with: .fade)
                    action.fulfill(with: .delete)
                    self.tblPendingLeaves.endUpdates()
                }




            }
        }

    }

    // customize the action appearance
    deleteAction.image = UIImage(named: "Delete")

    return [deleteAction]
}

1 个答案:

答案 0 :(得分:0)

我有同样的问题。 当我打电话给它删除时崩溃,并向我显示相同的错误。

我是什么: 从tableView中删除数据,然后从myDataSource中删除相同的数据(例如:从数组中删除数据)。这样可以处理您的情况,但不会刷新表。 (如果关闭并重新打开该项目,它将从表视图中删除它。)

因此,请检查数据与表之间的连接。

相关问题