views:

330

answers:

1

Hi,

Whenever i make a change in the objects in the first tab of my application the updates are automatically upated in tab 2 becuase it uses a fetchedResultsController. Now i have a third tab that should also update itself, but how can i do that?

I only have a nsmangedObjectContext in the third tab to get the appropriate data. How can i receive notifications whenever the objects in this context change?

I am also struggeling with the question how i can make my data fetching more efficient, becuase tab 2 and 3 use the same set of data. I am currently making another fetch in tab 3, to get the same data as tab 2. I dont know how i can use the data from tab2 without disturbing the fetchedresultscontroller.

Information on this subject would really be appreciated!!

A: 

If your tableviews are very closely related, then you can just have a single UITableViewDataSource that provides data for both of them, and have it manage the NSFetchedResultsController. From your description, this case seems very likely.

If the tableviews are not very similar, such that having a single UITableViewDataSource would create excessive if() logic, then move your NSFetchedResultsController into an separate model object and post NSNotifications when it receives delegate call-backs. Your UITableViewDataSources can then observe those notifications to update themselves when they are on-screen.

Rob Napier
Thanks for your information! But my third tab is not a table view. So i am dealing with a tableview(tab 2) and a regular view(tab 3). What should i do then..
Ton
In that case the latter solution above is likely easier to understand if you do not have a strong background in designing MVC. If I were doing it, I would probably make a single data object that was a datasource for both views, but that requires designing a datasource protocol for your second view and separating the tableview controller from the tableview datasource. Those aren't hard, but even so I might recommend going with my second design above since it is closer to Apple sample code.
Rob Napier