Switching between UITabBarController and UINavigationController
The main functionality of my application is controlled by the UITabBarController. However, I need to load a View that has a UINavigationController in it. When I return to my UITabBarController using
self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
My UITabBarController no longer responds to clicks. The View seems to have no focus.
However, if I use this code to switch back to 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 so it has to add a second copy of the view onto the stack. I'm right? Is there a way to use the first method and make my buttons respond? Please let me know.
a source to share
It looks like you are misrepresenting the Nav Controller. You definitely shouldn't add views directly to the window. You want to represent it with
[myTabBarController presentModalViewController:myNavController animated:YES];
When you're done with the navigation controller, you release it with
[myTabBarController dismissModalViewControllerAnimated:YES];
and everything should work.
BTW, this is all documented in the docs for UIViewController and the iPhone OS Programming Guide.
a source to share