删除 tableView 中的一行工作正常,直到它是最后一个现有行。然后我崩溃了:“由于未捕获的异常‘NSInternalInconsistencyException’而终止应用程序,原因:‘无效更新:第 0 部分中的行数无效。更新后现有部分中包含的行数(1)必须等于更新前包含在该部分中的行数 (1),加上或减去从该部分插入或删除的行数(0 插入,1 删除),加上或减去移入或移出该部分的行数( 0 搬入,0 搬出)。”
我知道有与预期不同的单元格数量及其在此功能中的数量:
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if categoryArray?.count == 0 { // <<-- i imagine this line cause problem, though deleting it will not let me show "no categories made yet" and while it would be better to use "if let" statement i make "array" in realm which never is nil as its being created with 0 elements(which is not nil)
return 1 …Run Code Online (Sandbox Code Playgroud)