UIViewController workflow management without modal, tabbar and navigationcontroller?
Hello stackoverflow fellows!
Please consider an UI workflow in iOS: One main viewcontrol开发者_StackOverflow社区ler and several other viewcontrollers branching out from there:
mainviewcontroller
+-viewcontroller 1
+-viewcontroller 2
+-viewcontroller 3
etc.
I would like to be able to switch and switch back from the main viewcontroller to one of the other viewcontrollers AND also switch BETWEEN the other viewcontrollers. All iOS patterns I know of seem to be problematic for that usecase:
UITabbarController would be the right choice if I could make the
tabbar disappear - it doesn't fit to the design. I was able to hide the bar, but the viewcontroller screens don't resize themselves and the whole thing feels hackish.UINavigationController is designed for a sequential order of
screens, also the slide-in animation doesn't fit to the designModal viewcontrollers are also meant for a sequential order, additionally I have to keep track of how many viewcontrollers are on the stack. Also, there is a timing problem with dismissing a view controller and immediately presenting the next one.
I could just switching views within a viewcontroller I guess, but the viewcontrollers have all kinds of subtasks to do. I would end up with one huge viewcontroller and lots of methods embedded for the different views.
My question: What would be the best approach to manage a bunch of viewcontrollers in any order I would like to?
Thanks for any help!
I would have a main UIViewController
. That one would have references to the other three UIViewControllers
. You can then do something like this from inside your main UIViewController
:
[self.view addSubview:view1.view];
This works, but I wouldn't advise you doing because it's not the natural way of doing it. As stated by apple:
You should not use view controllers to manage views that fill only a part of their window—that is, only part of the area defined by the application content rectangle. If you want to have an interface composed of several smaller views, embed them all in a single root view and manage that view with your view controller.
Ok, my solution is not perfect, but seems to work: Create a UINavigationController. Use the viewcontrollers: method to add a stack of viewcontrollers to your liking. When switching between viewcontrollers, rebuild the stack and attach again.
Problem: You only have the navigation controllers animation (slide in/out) at your disposal. But you can disable the navigationcontrollers animation, get the next viewcontrollers view, animate that in with a UIView animation, then switch to the view controller itself through stack building as explained above.
Really far from perfect, but works.
精彩评论