2014-10-07 3 views
1

두 항목이 삭제됩니다. (이들의 Obj-C입니다 미안하지만)여러 행을 삭제할 때 NSFetchedResultsController 대리자를 구현하는 방법은 무엇입니까?

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 (2), 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)

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '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 (2), 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).'

답변

2

당신은 '배치'도 다음과 같이 controllerWillChangeContentcontrollerDidChangeContent 대리자 메서드를 구현하여 업데이트를 수행해야합니다 삭제 라인에서

func controller(controller: NSFetchedResultsController!, didChangeObject anObject: AnyObject!, atIndexPath indexPath: NSIndexPath!, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath!) { 

    switch(type) { 
    case .Delete: 

     tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
    default: 
     break 
    } 
} 

나는이 오류 :

- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller { 
    [self.tableView beginUpdates]; 
} 

- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller { 
    [self.tableView endUpdates]; 
}