Should I have a NSFetchedResultsController in every view?

前端 未结 2 795
难免孤独
难免孤独 2021-02-03 11:47

I\'m using Core Data in my first iPhone application and trying to understand NSFetchedResultsController. It works great in my root view. Do I need to instantiate an instance in

相关标签:
2条回答
  • 2021-02-03 12:09

    I'd like to add that if you are using multiple NSFetchedResultsControllers for the same entity, but in different tables, your UITableView will not update if you insert data for the same entity using another controller. This is because your UITableView will not receive willChangeContent ,etc messages from an NSFetchedResultsController for which you have not set yourself as a delegate.

    0 讨论(0)
  • 2021-02-03 12:26

    If your other views are visualizing different Entities, then yes, you would use a different NSFetchedResultsController. You can basically get away with copy-and-pasting the code from the autogenerated root view controller for your other view controllers... just change the Entity name.

    However, if the other (table) views down your hierarchy are just displaying different attributes of the same Entity, it's more efficient/simpler to just pass the existing NSFetchedResultsController object down the hierarchy. Just create a NSFetchedResultsController member in the class interface and expose it as a property in the view controller's .h file, and then synthesize the property and release it in its .m file. Then set the property before you push the view controller on the stack.

    0 讨论(0)
提交回复
热议问题