我从我的 删除行时遇到问题tableView
,因为我有多个部分是在视图控制器出现时动态生成的,所以当我返回计数时,numberOfRowsInSection
它最终看起来像这样:
NSInteger count = [[_sectionsArray objectAtIndex:section] count];
return count;
现在,当删除时,我会生成相同类型的数组,如下所示:
NSMutableArray *contentsOfSection = [[_sectionsArray objectAtIndex:[indexPath section]] mutableCopy];
[contentsOfSection removeObjectAtIndex:[indexPath row]];
如您所见,我正在从未链接到的数组中删除对象tableView
,因此它只返回一个NSInternalInconsistencyException
有人可以帮我吗?
更新:
[contentsOfSection removeObjectAtIndex:[pathToCell row]];
if ([contentsOfSection count] != 0) {
// THIS DOESN'T
[self.tableView deleteRowsAtIndexPaths:@[pathToCell] withRowAnimation:UITableViewRowAnimationFade];
}
else {
// THIS WORKS!
[_sectionsArray removeObjectAtIndex:[pathToCell section]];
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:[pathToCell section]] withRowAnimation:UITableViewRowAnimationFade];
}