【发布时间】:2014-08-31 03:49:56
【问题描述】:
我在 Swift、iOS 8、Xcode 6 Beta 6 中从我的 tableView 中删除一行时遇到了一些问题。每次我尝试删除一行时,都会遇到类似
的错误-[UITableView _endCellAnimationsWithContext:] 中的断言失败, /SourceCache/UIKit_Sim/UIKit-3302.3.1/UITableView.m:1581 2014-08-30 20:31:00.971 类目录 [13290:3241692] *** 终止应用程序由于 未捕获的异常“NSInternalInconsistencyException”,原因: '无效更新:第 1 节中的无效行数。 更新 (25) 后包含在现有节中的行必须是 等于该节之前包含的行数 update (25),加上或减去插入或删除的行数 该部分(0 插入,1 删除)和加或减的数量 移入或移出该部分的行(0 移入,0 移出)。
我已经在这里阅读了这个常见问题的所有答案,并且觉得我已经满足了推荐的条件。项目似乎从数据模型中删除 - - 当我重新加载应用程序时,已删除的项目从表中消失了 - 但在适当的 sqlite 文件中似乎有一些残留物,当然数学并没有加起来。吐出 indexPath 的 println 显示了正确的 Section 和 Row。我很困惑。这应该很简单,但我确信我错过了一些愚蠢的东西,我怀疑在数据模型删除中。 Github 上的完整项目。
func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
return fetchedResultController.sections.count
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
return fetchedResultController.sections[section].numberOfObjects
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
let cell = tableViewMain.dequeueReusableCellWithIdentifier("CellMain", forIndexPath: indexPath) as UITableViewCell
let personForRow = fetchedResultController.objectAtIndexPath(indexPath) as Person
cell.textLabel.text = personForRow.fullName()
return cell
}
func tableView(tableView: UITableView!, canEditRowAtIndexPath indexPath: NSIndexPath!) -> Bool {
return true
}
func tableView(tableView: UITableView!, editingStyleForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.Delete
}
func tableView(tableView: UITableView!, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath!) {
println("section and row \(indexPath.section) \(indexPath.row) ")
if (editingStyle == UITableViewCellEditingStyle.Delete) {
let personForRow : NSManagedObject = fetchedResultController.objectAtIndexPath(indexPath) as Person
context?.deleteObject(personForRow)
context?.save(nil)
tableViewMain.beginUpdates()
tableViewMain.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
tableViewMain.endUpdates()
}
【问题讨论】:
-
不重复。对此的答复不充分。
标签: ios xcode uitableview swift ios8