I'm working on a little app to get the grips with Objective-C and the UIKit. My application shall simply display the menus for every weekday that are served at the individual canteens at my university.
I have a view containing a UIToolbar which itself contains a UISegmentedControl to switch between the days. The remaining screen space shall be used for the Table View displaying the dishes served by one canteen at a certain weekday. Now, how do I do this?
I have a Canteen that has 5 Menus (one for every day) and each of these Menus contains an arbitrary number of Dishes. The business logic is actually working totally fine by now.
How do I connect my views to my business logic. In my opinion, there are three possible ways and I have no idea which 开发者_开发知识库one I should choose:
My
CanteenController- which owns theUIToolbarmentioned above - does everything. It implements the protocols necessary to manage aUITableViewand it owns theUITableViewthat displays the dishes.I have a
MenuControllerthat uses theCanteenController'sUITableView- so theUITableViewis shared among the 5MenuControllers.I have 5
MenuControllersthat have there very ownUITableViewsand every time I switch between days I replace the currentUITableViewof myCanteenControllerwith the right one.
Is there such thing as a correct solution for this problem? I think, all of these solutions should work, but maybe I should prefer one of them.
Any of these solutions will work, and in most cases none of them will cause performance or memory issues. One advantage to option 3 is that you could easily fade between them upon selection with
[UIView animateWithDuration:0.5 animations:^{ /*show new top view by setting alpha from 0 to 1 and bring it to the front*/ }];
1 - would be my pick, and reload the data of the table when a new toolbar item is selected. this allows for less memory to used, which is numero uno stipulation when looking at Apple documentation...Don't use anymore memory than you have to."
2 - doesn't make sense to me
3 - i think would be better handled by a TabBarController that automatically does the view switching for you between each view controller.**
加载中,请稍侯......
精彩评论