起初我的表格視圖是空的,然後你可以添加你自己的單元格。當你刪除這些單元格時,一切正常。但是,如果你刪除最後一個單元格,然後我的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