简体   繁体   中英

tableView and normal view (same data object)

I don't know how I can share the same data between two tab bar items. One tab uses nsfetchedresultscontroller and the other table is just a normal view that should use the same data as my fetchedresultscontroller.

If i had two normals views, I would just make my object a singleton, and let the tableview and normal view use the same data.

But now i have a fetchresultscontroller and a normal view. I was thinking about just using another fetchedresultscontroller for my normal view, so I have all the features such as fetch cache, notifications and such..

I know fetchresultscontroller should be used for tableview, but I guess I can use it for non tableviews as well.

Somebody knows what it is I should do? I couldn't find documentation from apple on this matter.

Your data should have noting to do with your viewControllers or views - that is, if you follow the MVC style. If your data is only available in one viewController and you don't want to extract it out into its own class, then provide methods in your viewController that can be called by the other viewController to get the data.

For example, have methods like this:

- (NSString) getNameOfSelectedUserAtIndex:(int) index;
- (int) getCountOfSelectedUsers;
- (NSSArray) getResults;

And then from within your other viewController, call:

string = [fetchedresultscontroller getNameOfSelectedUserAtIndex:i];
count = [fetchedresultscontroller getCountOfSelectedUsers];
array = [fetchedresultscontroller getResults];

You have to make sure you add fetchedresultscontroller as an instance variable to your other viewController and set it probably in its viewDidLoad.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM