Multiple root view controllers for UINavigationController?

You may not need an intermediate UIViewController.

Up vote 0 down vote favorite share g+ share fb share tw.

I'm trying to switch between several table views as the root of a navigation controller. Depending on the settings of my app, I want to use different sets of data with different methods, and prefer to have these encapsulated in separate classes. My thought was to set a view manager class (UIViewController) as the root view controller of the navigation controller.

In the view manager we check the settings to see which view we want to load: if(application_mode intValue==APPLICATION_MODE_A){ AViewController *aView = DeviceTableViewController alloc init; self. View insertSubview:aView. View atIndex:0; } else if(application_mode intValue==APPLICATION_B){ BViewController *bView = BViewController alloc init; self.

View insertSubview.bView. View atIndex:0; } That does in fact insert the appropriate view into the view manager, at the cost of a white bar at the top of the inserted view and no info on the navigation bar, ie the subview is not connected to the navigation controller. What's the proper way to do this?

I'd really prefer not to have one ginormous table view! Iphone ios uiviewcontroller uinavigationcontroller link|improve this question asked Sep 20 '11 at 16:06nflacco675110 85% accept rate.

You may not need an intermediate UIViewController I would do at the beginning : //navigationController comes from a Xib or previous code if(application_mode intValue==APPLICATION_MODE_A){ AViewController *aView = DeviceTableViewController alloc init; navigationController. RootViewController = aView; aView release; } else if(application_mode intValue==APPLICATION_B){ BViewController *bView = BViewController alloc init; navigationController. RootViewController = bView; bView release; }.

I set the navigation controller's root view controller in the app delegate. If I set the root view controller to be A or B, doesn't that get rid of the manager? I want to be able to change from A, B at will.

– nflacco Sep 20 '11 at 17:09 Wich manager are you talking about? – Zoleas Sep 21 '11 at 8:43 the manager class that I mentioned in the OP... the class that controlls which of the subviews we go to – nflacco Sep 21 '11 at 16:06 are you sure you need that manager? When do you know that you want to change your "Application mode"?

If it is a viewController, when do you see it's view? – Zoleas Sep 21 '11 at 16:18 the structure of the application is a tab controller, one tab being the navigation controller, the other tab being data selection. Depending on which data is selected, I want the nav controller's root view to be one of 3 different table views, each which manipulate the data in different ways and have different methods.

I could wrap it into one big table view, but it's way less maintainable that way. The manager is the layer between the navigation controller and the 3 table views. – nflacco Sep 21 '11 at 19:50.

Since there is no view controller containment, I like the approach outlined in Jonah William's blog: blog.carbonfive.com/2011/03/09/abusing-u... You can't effectively place a view controller inside another; instead, we create something with similar lifecycle methods (viewDidLoad, viewDidAppear, etc) and forward those methods from the parent to the child. This 'psudo-viewcontroller' has a view property that we add as a subview to the parent's view, using UIView addSubView developer.apple.com/library/ios/#documen...: With this approach, we can encapsulate view elements, switch them out dynamically in a view controller, place several within a single view controller, etc. This way they can be considered separately from your navigation stack. It's a bit of work, but the cleanest UI encapsulation approach in iOS 4 in my opinion.

I will try this when I get home from work – nflacco Sep 20 '11 at 20:54.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions