18

Questo è il codice, ho salvare il modello via Magico:NSFetchedResultsController chiama didChangeObject eliminare invece di aggiornamento

MagicalRecord.saveWithBlock({ (localContext) -> Void in 
        var localNotification = CDNotification.MR_findFirstByAttribute("notificationID", withValue: notification.notificationID, inContext: localContext) as CDNotification 
        localNotification.readNumber = NSNumber(bool: true) 
       }) 

Delete è chiamato al posto di aggiornamento dopo il codice precedente si chiama:

func controller(controller: NSFetchedResultsController, didChangeObject object: AnyObject, atIndexPath indexPath: NSIndexPath, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath) { 
    switch type { 
    case NSFetchedResultsChangeType.Insert: 
     self.tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Fade) 
    case NSFetchedResultsChangeType.Update: 
     if let cell = self.tableView.cellForRowAtIndexPath(indexPath){ 
      self.configureCell(cell as TableViewCell, atIndexPath: indexPath, withNotification: object as CDNotification) 
     } 
     self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
    case NSFetchedResultsChangeType.Move: 
     self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
     self.tableView.insertRowsAtIndexPaths([newIndexPath], withRowAnimation: .Fade) 
    case NSFetchedResultsChangeType.Delete: 
     self.tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
    default: 
     return 
    } 
} 

Ciò avviene solo se ho impostato il predicato per prendere richiesta, nell'esempio:

fetchRequest.predicate = NSPredicate(format:"user == john") 
+0

ESATTAMENTE :-) Lo stesso problema. Hai trovato la risposta? –

+0

C'è qualche soluzione per questo? Questo è un bug serio. Vorrei verificare all'interno del caso DELETE se è stato davvero rimosso dal database, ma è stato rimosso da 'NSFetchedResultsController', quindi non so quale oggetto dovrei controllare se esiste in Core Data. Qualche idea? –

+0

Ho lo stesso problema qui: http://stackoverflow.com/questions/32377070/nsfetchedresultscontroller-remove-row-from-uitableview-after-update-relationship. Ma aggiorno le relazioni anziché la proprietà. Lo stesso problema. –

risposta

4

che cosa è succede qui che invece dell'evento di modifica NSFetchedResultsChangeUpdate ti aspetti, stai ottenendo un NSFetchedResultsChangeDelete seguito da NSFetchedResultsChangeInsert. È inoltre possibile vedere uno NSFetchedResultsChangeMove con lo stesso indexPath come origine e destinazione. Questo è un problema noto in several beta versions of iOS 922380191 e altri.

+0

Quindi, non c'è alcuna soluzione per questo? C'è un modo per risolvere questo o no? –

+0

Archivia un radar e potrebbe essere riparato. Se si utilizzano correttamente contesti figlio genitore senza bloccare questo non sembra stimolare. – quellish

+0

Contesto genitore-figlio? Cosa intendi esattamente? Il contesto 'NSFetchedResultsController' dovrebbe essere il contesto padre per il contesto in' saveWithBlock'? –

Problemi correlati