【发布时间】:2015-10-20 17:33:40
【问题描述】:
我有一个表视图,它有一个段控制器,它分别有两个段类别 1 和 2。当我将一个项目添加到类别 1 时,它完美地完成了,但是当我将一个项目添加到类别 2 时,它使应用程序崩溃,说'由于未捕获的异常'NSInternalInconsistencyException'而终止应用程序',原因:'尝试将第 0 行插入第 0 节,但更新后第 0 部分只有 0 行。 这是我插入表格视图的代码。
对于第 1 类:
func itemDetailViewController(controller: ItemDetailViewController, didFinishAddingItem item: NoToDoItem) {
let newRowIndex = items.count
items.append(item)
let indexPath = NSIndexPath(forRow: newRowIndex, inSection: 0)
let indexPaths = [indexPath]
tableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: .Automatic)
dismissViewControllerAnimated(true, completion: nil)
}
对于第 2 类:
func itemDetailViewController(controller: ItemDetailViewController, didFinishAddingNotSureItem notSureItem: NotSureItem) {
let newRowIndex = notSureItems.count
notSureItems.append(notSureItem)
let indexPath = NSIndexPath(forRow: newRowIndex, inSection: 0)
let indexPaths = [indexPath]
tableView.insertRowsAtIndexPaths(indexPaths, withRowAnimation: .Automatic)
dismissViewControllerAnimated(true, completion: nil)
}
【问题讨论】:
-
那么您创建实例并使用它们填充表格视图的其他代码呢
-
paste.ubuntu.com/12874960。这是我的其他代码@Wain
-
您似乎没有为第二个类别表填充数据源数组,您是否在委托方法中使用断点进行调试?
-
尝试使用 beginUpdates() 和 endUpdates() 插入新行。其他一切似乎都很好。
-
在添加 beginUpdates 和 endUpdates @BhaumikDesai 后它给了我同样的崩溃
标签: ios swift uitableview uisegmentedcontrol