I have a very general question regarding MVCs. I have an app which uses tab bar controller to show different kinds of data from a web service.
I have a “model” class which does all the dirty work like fetching data and modifying it for presentation, but I’m instancing that class in each MVC. And here is where the trouble comes. For example, two of the tabs of the app are Sales and Comments. When the app launches I want it to fetch and display Sales, and also fetch Comments and put a badge on the comments tab if there are new comments.
That fetching process involves pulling data from a web service, storing it to core data, pulling from cache, comparing, etc etc. And it gets ugly when the user taps Comments, but they are still fetching in the Sales tab (just for that badge). And when Comments comes up, Sales MVC is dead and I can’t tell it anything to prevent it from screwing up.
My question is, how can I make the “brain” class independent from the MVCs? Meaning that I don’t want to have a brain for each MVC (which doesn’t make sense), but only one for all MVCs and use delegation to push data and badges and stuff? I have thought about subclassing the UITabBarController and stick the brain class there, but I’m not sure if it’s a good practice to do it like this.
Any thoughts?
There is absolutely no problem with subclassing of
UITabBarController.Just go ahead and place fetch logic there. After fetching, you can update tab controllers and tab badges.
P.S. In my app I just simply placed logic in first tab controller, and then updated other tab controllers accessing it like
self.tabBarController.tabBar.items[1].Also, I added to tab controllers other than first:
and looking for core data changes: