2017-06-14 98 views
1

你好我使用SwipeCellKitUITableView。我想在刷单元格时进行删除操作。这是我如何处理删除部分。 self.deleteLeave()正在调用Web服务并删除服务器端中所选的离开条目。那么,如果它在服务器端成功删除我想删除从当前数组对象和更新我UITableView。但我的问题是,当我轻扫,然后点击删除按钮,否则拖着它在一定程度上的应用程序被赋予一个异常崩溃。SwipeCellKit崩溃时尝试删除

错误

终止应用程序由于未捕获的异常 “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] 
} 
+0

我有同样的问题。你修好了吗? – Codey

回答

0

我删除了下面的方法,该bug已得到解决。

func numberOfSections(in tableView: UITableView) -> Int { 
}