我使用NSFetchedResultsController來填充tableview,並且每件事情都可以(添加deletng ..)但每當我嘗試從tableview中刪除最後一行時(當tablview中只有一行時無法從fetchedResultsController中刪除最後一個對象
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:1037
2012-08-03 16:32:39.667 MackaWithCoreData[793:15503] CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out). with userInfo (null)
據我看到的,後刪除對象時的委託方法嘗試重新加載tableview中,因爲fetchedResultsController爲null,導致系統崩潰。如何處理這個問題:)應用程序與下面的崩潰日誌問題?在此先感謝
編輯controller controllerDidChangeContent:..
的實施。方法是低於
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
newIndexPath:(NSIndexPath *)newIndexPath
{
switch(type)
{
case NSFetchedResultsChangeInsert:
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
break;
case NSFetchedResultsChangeDelete:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
XLog(@"the row removed from tv");
break;
case NSFetchedResultsChangeUpdate:
// [self configureCell:[self.tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
break;
case NSFetchedResultsChangeMove:
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
XLog(@" object deleted from fetchedresultscontroller");
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath]withRowAnimation:UITableViewRowAnimationFade];
break;
}
}
能否請您告訴我們您的控制器的'執行:didChangeObject:atIndexPath:forChangeType:newIndexPath:' – Daniel 2012-08-03 13:51:59
@Daniel請看看我的編輯 – ilhnctn 2012-08-03 14:07:26
你實現'控制器:didChangeObject:atIndexPath: forChangeType:newIndexPath:'?這是針對單元的 - 您的實現是針對單元的。 – Daniel 2012-08-03 14:11:21