“试图删除行...”崩溃,但我不是故意删除任何行

时间:2019-07-11 00:33:09

标签: ios swift uitableview

所以我得到了:

2019-07-10 13:33:49.054504-0700 akin[60767:2710637] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 2 from section 0 which only contains 1 rows before the update'

当我在项目中搜索deleteRows时,什么也没有出现。

这是堆栈跟踪: enter image description here

这是我的堆栈跟踪代码

@objc func handlePillTap(sender: UITapGestureRecognizer) {
    let oldContext = movingPillRight.isActive ? "romance" : "social"
    let sideTouched: Side = sender.location(in: movingPill).x > movingPill.frame.width / 2 ? .right : .left
    updateModelContext(with: sideTouched)
    styleView(importance: questionCellDelegate?.importance())
    movePill(sideTouched)
    let newContext = movingPillRight.isActive ? "romance" : "social"
    if oldContext != newContext {
        pillDelegate?.changeContext(Context(rawValue: newContext)!)
    }
    guard let delegate = questionCellDelegate else {return}
    updateViewOfCell(from: delegate.question,
                         currentContext: currentQuestionContext,
                     delegate: pillDelegate as? UIViewController)
}
func changeContext(_ context: Context) {
    currentQuestionContext = context
    topBar.context = currentQuestionContext
    responseTV.safelyReload(
    questionsWrapper.question.responses.indexPaths, with: .fade )
}
func safelyReload(_ rows: [IndexPath], with animation: RowAnimation) {
    DispatchQueue.main.async {
        self.reloadRows(at: rows, with: animation)
    }
}

我不知道为什么要得到这个错误。

1 个答案:

答案 0 :(得分:0)

我在numberOfRows中返回的行数不等于reloadRows(at:的传入indexPaths计数