繁体   English   中英

NSInternalInconsistencyException:带有部分的tableView中的无效更新

[英]NSInternalInconsistencyException: Invalid update in tableView with sections

我有一个UITableView带有要从中删除行的部分。 从BubbleWrap切换到AFMotion时,我开始遇到一些不可变的数组错误。 通常,它们可以通过在推送其视图控制器之前在要更改的对象上附加mutableCopy来修复。 但是,对于带有节的表,我克服了冻结/不可变的数组错误,但得到了NSInternalInconsistencyException: Invalid update: invalid number of rows in section 0 我看到了有关这些的其他问题,并尝试添加beginUpdatesendUpdates等,但仍然无法正常工作。

我的数据对象是一个哈希,看起来像这样:

{
  "Items" => ["one", "two", "three"],
  "More"  => ["four", "five", "six"]
}

提交数据时,我会将其传递给新的控制器:

def tap_items(sender)
  controller        = ItemsController.alloc.initWithNibName(nil, bundle:nil)
  controller.data   = @data[:items].mutableCopy
  self.presentViewController(
    UINavigationController.alloc.initWithRootViewController(controller),
    animated:true,
    completion: lambda {}
  )
end

然后在ItemsController我的表设置为使用以下命令删除行:

def tableView(tableView, commitEditingStyle:editingStyle, forRowAtIndexPath:indexPath)
  if editingStyle == UITableViewCellEditingStyleDelete
    rows_for_section(indexPath.section).delete_at indexPath.row
    tableView.deleteRowsAtIndexPaths([indexPath],
      withRowAnimation:UITableViewRowAnimationFade)
  end
end

但这会引发内部不一致异常错误。 我也尝试过data[sections[indexPath.section]].delete_at indexPath.row而不是rows_for_section(indexPath.section).delete_at indexPath.row 但这并没有任何改变。

更新:这是我的tableView的代码

def viewDidLoad
  super

  @table = UITableView.alloc.initWithFrame(self.view.bounds)
  @table.autoresizingMask = UIViewAutoresizingFlexibleHeight
  self.view.addSubview(@table)

  @table.dataSource = self
  @table.delegate = self
end

def sections
  data.keys.sort
end

def rows_for_section(section_index)
  data[self.sections[section_index]].mutableCopy
end

def row_for_index_path(index_path)
  rows_for_section(index_path.section)[index_path.row]
end

def tableView(tableView, titleForHeaderInSection:section)
  sections[section]
end

def numberOfSectionsInTableView(tableView)
  self.sections.count
end

def tableView(tableView, numberOfRowsInSection: section)
  rows_for_section(section).count
end

听起来好像您没有在引用正确的dataSource实例。 您没有显示要在哪里分配它,即tableView.dataSource = data ,也没有显示rows_for_section的代码。 我想知道它是否与.mutableCopy 由于某种原因,这是否必要?

在我的应用程序中,我直接从tableView中获取dataSource,即tableView.dataSource

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM