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 theUIToolbar
mentioned above - does everything. It implements the protocols necessary to manage aUITableView
and it owns theUITableView
that displays the dishes.I have a
MenuController
that uses theCanteenController
'sUITableView
- so theUITableView
is shared among the 5MenuControllers
.I have 5
MenuControllers
that have there very ownUITableViews
and every time I switch between days I replace the currentUITableView
of myCanteenController
with 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.**
精彩评论