views:

652

answers:

1

The main functionality of my app is controlled by a UITabBarController. However, I need to load a View that has a UINavigationController. When I return to my UITabBarController using

     self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];

My UITabBarController no longer responds to clicks. It seems like the View does not have focus.

However, if I use this code to switch back to the UITabBarController:

[window addSubview:tabBarController.view]

My buttons will respond. I feel like "addSubview" is less efficient because I never remove the view from the window and therefore it must be adding a second copy of the view to the stack. Am I correct? Is there a way to use the first method and make my buttons respond? Please let me know.

+1  A: 

It sounds like maybe you're presenting the Nav Controller incorrectly. You definitely shouldn't be adding views directly to the window. You want to present it using

[myTabBarController presentModalViewController:myNavController animated:YES];

When you're done with the nav controller you dismiss it with

[myTabBarController dismissModalViewControllerAnimated:YES];

and everything should work.

BTW, this is all documented in the docs for UIViewController and the "View Controller Programming Guide for iPhone OS" document.

n8gray
n8gray... you just saved my life. Perfect. I was simply opening the nav controller wrong. I really appreciate it. You may want to edit the post to remove that dash in this line: [myTabBarController - dismissModalViewControllerAnimated:YES];
Dave
Oops! Yes, you're right of course. Edited. Happy to help!
n8gray