起初我的表格视图是空的,然后你可以添加你自己的单元格。当你删除这些单元格时,一切正常。但是,如果你删除最后一个单元格,然后我的NSMutableArray中有没有对象,我在我的控制台得到这个错误(也,我使用的核心数据,以节省电池):当数组为空时停止Tableview崩溃?
*** 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];
}
}
我将如何解决这个问题?
为什么每次在索引0处删除对象? – SALMAN 2012-07-21 15:25:28