【发布时间】:2017-07-11 16:06:42
【问题描述】:
我的应用中有一个表格视图,我已将其设置为在两种不同的查看模式之间切换。按下按钮时,表格视图会更改为显示已完成的任务,而不是需要注意的任务。切换此项按预期工作,直到您将任务标记为完成或未完成。在此之后,下次用户按下显示完成任务按钮时,应用程序将崩溃并给出此错误:
-[UITableView _addPendingSwipeDeletionShadowUpdateForSection:] 中的断言失败,/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3688.4/UITableView.m:15334
由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView 内部不一致:添加影子更新时 _swipedIndexPath 不能为 nil”
我知道错误说明了阴影和滑动索引路径,但我没有弄乱表格视图的阴影,所以我不确定问题出在哪里,特别是因为几天前它工作得很好。我在完整数据和不完整数据之间切换的代码是这样的:
tableView.beginUpdates()
if showComplete {
showComplete = false
if completedArray.count != 0 {
tableView.deleteSections(NSIndexSet.init(index: 0) as IndexSet, with: .fade)
}
if taskArray.count != 0 {
allComplete()
}
else {
tasksIncomplete()
tableView.insertSections(NSIndexSet.init(indexesIn: NSMakeRange(0, taskArray.count)) as IndexSet, with: .fade)
}
}
else {
showComplete = true
if taskArray.count != 0 {
tableView.deleteSections(NSIndexSet.init(indexesIn: NSMakeRange(0, taskArray.count)) as IndexSet, with: .fade)
}
if completedArray.count == 0 {
allComplete()
}
else {
tasksIncomplete()
tableView.insertSections(NSIndexSet.init(index: 0) as IndexSet, with: .fade)
}
}
tableView.endUpdates()
allComplete() 和 tasksIncomplete() 函数只是在没有数据可查看或添加新数据时隐藏和显示 tableView。我完成任务的代码如下:
self.tableView.beginUpdates()
self.completedArray.append(thisTask)
self.taskArray[indexPath.section].remove(at: indexPath.row)
if self.taskArray[indexPath.section] == [] {
self.taskArray.remove(at: indexPath.section)
self.dynamicSectionHeaders.remove(at: indexPath.section)
self.tableView.deleteSections([indexPath.section], with: .left)
}
else {
self.tableView.deleteRows(at: [indexPath], with: .automatic)
}
self.tableView.endUpdates()
标记任务未完成的代码是:
self.tableView.beginUpdates()
self.completedArray.remove(at: indexPath.row)
if self.completedArray.count == 0 {
self.tableView.deleteSections([0], with: .left)
}
else {
self.tableView.deleteRows(at: [indexPath], with: .automatic)
}
self.sortIncompleteTaskArray()
self.tableView.endUpdates()
taskArray 是一个二维数组,包含节和实际数据。 completedArray 只是一维的。任何帮助将不胜感激。我已经查看了所有内容,似乎从未记录过此错误。谢谢。
【问题讨论】:
标签: ios iphone swift uitableview