起初我的表格视图是空的,然后您可以向其中添加自己的单元格。当您删除这些单元格时,一切正常。但是,如果您删除最后一个单元格,则我的 NSMutableArray 中没有对象,并且我在控制台中收到此错误(另外,我正在使用 Core Data 保存单元格):
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[_PFBatchFaultingArray objectAtIndex:]: index (123150308) beyond bounds (1)'
我也尝试输入这行代码,但我仍然得到相同的结果:
//arr is my mutable array
if ([arr count] == 0) {
NSLog(@"No Cells");
}
这就是我从表视图中删除对象的方式:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[arr removeObjectAtIndex:0];
[context deleteObject:[arr objectAtIndex:0]];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
我将如何解决这个问题?