當我在TabbarController中的兩個選項卡之間切換到包含NSFetchResultsController的Viewcontrollers時。然後NSFetchResultsController -controllerDidChangeContent:嘗試爲userInfo創建兩個單元格的動畫
CoreData: error: Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Attempt to create two animations for cell with userInfo (null)
我的tableview變成白色,崩潰,如果我嘗試更新的數據:在我viewcontrollers的一個更新的東西時,我得到了以下核心數據錯誤。
我-controllerDidChangeContent:看起來是這樣的:
視圖控制器(在我更新的數據視圖 - 控制)。
-(void)controllerWillChangeContent:(NSFetchedResultsController*)controller { [self.productDetailTableView beginUpdates]; } -(void)controllerDidChangeContent:(NSFetchedResultsController*)controller { [self.productDetailTableView endUpdates]; } -(void)controller:(NSFetchedResultsController*)controller didChangeSection:(id<NSFetchedResultsSectionInfo>)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { UITableView *tableView = self.productDetailTableView; switch (type) { case NSFetchedResultsChangeInsert: [tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeDelete: [tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; break; } } -(void)controller:(NSFetchedResultsController*)controller didChangeObject: (id)anObject atIndexPath:(NSIndexPath*)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath*)newIndexPath { UITableView *tableView = self.productDetailTableView; NSIndexPath *tvIndexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:(indexPath.section + 1)]; NSIndexPath *tvNewIndexPath = [NSIndexPath indexPathForRow:newIndexPath.row inSection:(newIndexPath.section + 1)]; indexPath = tvIndexPath; newIndexPath = tvNewIndexPath; switch (type) { case NSFetchedResultsChangeInsert: [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeDelete: [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeMove: [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationNone]; break; } }
Viewcontroller(此視圖控制器,其中TableView變白併發生錯誤)。
-(void)controllerWillChangeContent:(NSFetchedResultsController *)controller { [self.cartTableView beginUpdates]; } -(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { UITableView *tableView = self.cartTableView; switch(type) { case NSFetchedResultsChangeInsert: [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationNone]; break; case NSFetchedResultsChangeDelete: [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; break; case NSFetchedResultsChangeUpdate: [self configureCell:(ProductCell *)[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath]; break; case NSFetchedResultsChangeMove: [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; [tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationNone]; break; } } -(void)controller:(NSFetchedResultsController *)controller didChangeSection:(id)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type { UITableView *tableView = self.cartTableView; switch(type) { case NSFetchedResultsChangeInsert: [tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; break; case NSFetchedResultsChangeDelete: [tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; break; } } -(void)controllerDidChangeContent:(NSFetchedResultsController *)controller { [self.cartTableView endUpdates]; }
怎樣才能解決這個問題,並得到了「嘗試創建兩個動畫細胞與USERINFO」走開,什麼是這種情況出現的原因嗎?
您是否使用兩個視圖控制器相同的NSFetchedResultsController對象? –
沒有2個獨立的NSFetchedResultsControllers。但是同樣的NSMangedObjectContext。 – 7c9d6b001a87e497d6b96fbd4c6fdf
你是否同時更新了兩個視圖控制器? –