开发者

Double entry in table view

I seem to have the same problem than here: How to avoid data lose when UIImagePickerController unloads my controller?

I have the same issue, but it's a UITableViewController. I use Core Data and NSFetchedResultsController, using the -controllerWillChangeContent, -controller:didChangeSection:atIndex:forChangeType:, -controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:, and -controllerDidChangeContent (as in the iPhoneCoreDataRecipes sample code).

My problem is that in the -viewDidLoad开发者_运维问答, I do a -performFetch, that reloads the tableView properly (if I added an element with the image picker as modal view, it is taken into account, etc.). But then, the aforementioned methods are called, and performs the operation (an insertion) for the second time! So I end up with the table view containing a double entry for one object in the Core Data base. If I relaunch the app, I only have one entry, so it's definitely a UI updating problem.

Any idea?


Finally, I used a second managed object context. I save to the persistent store through this context, and update the main context, for the NSFetchedResultsControllerDelegate methods to get called. It's exactly what the CoreDataBooks sample implemented.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜