0

I have my viewControllers like this:


startViewController ------> menuViewController 
                                          \
                                           \ ------> ImportantViewController

From startMenu I pushed menuView then I pushed again importantView, on that I have made importantView as my rootViewcontroller for it to become my parent view like as below:

UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: vc];
[self presentModalViewController: navControl animated: YES];

From that I pushed view after importantView via:

[self.navigationController pushViewController:vc animated:YES];

Now my prob is like this:

enter image description here

ImportantVIew as my rootView pushed to menuView pushed to ViewA then pushed to View B then option whether to return to menuView or return to ViewA.

My question is: I want to make my ViewB as a rootView, then when I go to ImportantView it will then return it to as rootView. Is it possible to have 2 rootView? Or I need to just replace each other?

Help would be much appreciated. Thanks.

Bazinga
  • 2,456
  • 33
  • 76

1 Answers1

1

What is the reason for changing the root view controller all the time?

With viewA and viewB calling in circle you would build up an endless stack of view controllers. That is probably not what you want to do.

Take a step back and re-think what you are trying to achive. Do you just want to change between viewA and viewB? In that case you sould go for a different architecture/pattern than the usual pushViewController thing. Read a bit about removeFromParentViewController or transitionFromViewController:toViewController:. Or get familiar with manipulating the chain of view controllers yourself. Those things might help achieving the user experience that you want to create without building up an endless stack of view controllers.

Hermann Klecker
  • 14,039
  • 5
  • 48
  • 71
  • I just need to transition between View A and View B, then I need to retain View B all the time when the views are navigating to each other, – Bazinga Jul 11 '12 at 08:56
  • 1
    Well, then look for transitionFromViewController:... It is certainly one option to achieve that. You may opt for dealing with modal view controllers, which too provides methods for achieving exactly that. You can later re-instate those view controller that was hidden recenty without creating and initializing a new one each time. – Hermann Klecker Jul 11 '12 at 09:01
  • I do not mind, of course, but I do not have it handy, unfortunately. Sorry. (Different project - no access to iphone code/different location - no access to home resources) – Hermann Klecker Jul 12 '12 at 08:16
  • I mean that I cannot provide any code because I do not have access to good examples. You may find some useful information here where somebody asked a similar question: http://stackoverflow.com/questions/11363337/uiviewcontroller-transition-objective-c For that one you would need to work in iOS 5.x or higher. This video tutorial might help: http://www.youtube.com/watch?v=p8XHhQ8oU-g . This one is even more basic: http://www.youtube.com/watch?feature=iv&src_vid=p8XHhQ8oU-g&annotation_id=annotation_736280&v=ph3XhJD8QAI – Hermann Klecker Jul 12 '12 at 08:33