1

我正在使用ECSlidingViewController進行路徑& FB樣式的UI。兩個UITableViews,其中一個(細節)顯示爲主視圖,第二個(主人)顯示爲sidemenu。兩者都由Core Data提供支持。核心數據在刪除父表格時崩潰

我在刪除sidemenu UITableView中的父錶行時遇到了嚴重的崩潰,但僅當詳細信息頁面在刪除時顯示父行的子級時纔會發生硬性崩潰。所有其他行按預期刪除。

刪除該行被處理:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     [self.managedObjectContext deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]]; 
    } 
} 

我得到的日誌中出現以下錯誤:

CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (3), 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)

delete rule設置爲抵消是否有幫助?

我猜核心數據一次從NSFetchedResultsController刪除所有的孩子,然後UITableVIew得到所有困惑?

如何在沒有崩潰的情況下刪除父級和子級NSManagedObjects?

+0

刪除對象後,執行新的讀取和重新加載數據。你也可以使用NSFetchResultsControllerDelegate。希望能幫助到你。 – 2013-05-12 18:28:12

+0

我無法刪除沒有崩潰的對象。單個項目刪除工作正常。我不明白爲什麼它試圖一次刪除所有的子項目。 – JMWhittaker 2013-05-12 19:29:35

回答

0

經過代碼很多次,事實證明,我嵌套[self.tableView beginUpdates][self.tableView endUpdates]這是不同步的,我連續兩次調用endUpdates。

我已經打了很多次現在開發這個程序。如果你有這樣的崩潰檢查,你可能使用CS193P課程的CoreDataTableViewController檢查你使用beging和結束更新!