尝试删除时 SwipeCellKit 崩溃
Posted
技术标签:
【中文标题】尝试删除时 SwipeCellKit 崩溃【英文标题】:SwipeCellKit crash when try to delete 【发布时间】:2017-06-14 10:52:27 【问题描述】:您好,我正在使用SwipeCellKit 作为我的UITableView
。我想在滑动单元格时进行删除。这就是我处理删除部分的方式。 self.deleteLeave()
正在调用 Web 服务并在服务器端删除选定的休假条目。然后,如果它在服务器端成功删除,我想从当前数组中删除该对象并更新我的UITableView
。但是我的问题是,当我滑动并单击删除按钮或将其拖动到某种程度时,应用程序会因异常而崩溃。
错误
由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',原因:'无效更新:无效 第 0 节中的行数。包含在第 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】:我也有同样的问题。 当我调用 delete 时,它崩溃并显示相同的错误。
我的意思是: 从 tableView 中删除数据,然后从 myDataSource 中删除相同的数据(例如:从数组中删除数据)。这将处理您的情况,但不会刷新表格。 (如果您关闭并重新打开项目,它将从表格视图中删除)。
所以检查你的数据和你的表之间的连接。
【讨论】:
以上是关于尝试删除时 SwipeCellKit 崩溃的主要内容,如果未能解决你的问题,请参考以下文章
iPhone - 在删除 CoreData 中的对象后尝试保存新对象时应用程序崩溃