Can you push a UITabBarController inside an UINavigationController

ios, iphone, objective-c, xcode

Solution

Simply putting it, YES you can.

But simply because you can, does not mean you should. The `UITabBarController` is intended to be used as a viewController at the root level (as the rootViewController of the app window). The aim is to provide the user with the best(and easy) UX. Apple advises to keep the view hierarchy of your app such that there is only one 'path' from one view controller to another.

The widely accepted way of using a `UITabBarController`is to set it as the `rootViewController`, and assign `UIViewControllers` to each 'tab'. If you want to be able to push/pop from these view controllers, you assign a `UINavigationController` to each tab, with their own `rootViewController`s instead, just like the Facebook app for iOS.

If you do decide to push it onto a `UINavigationController` it would be advised to use simple `viewControllers` in each tab, rather than `UINavigationController`s, to avoid multiple view hierarchies. The rest is upto you as a developer. In no scenario, should ease-of-coding affect the end user's experience. The priority is always the latter.

EDIT:

Create a `UITabBarController`.

You set the root view controllers for each tab using:

tabBarController.viewControllers = [NSArray arrayWithObjects:
                                         alphaController,
                                         betaController,
                                         nil];

Push it onto your navigation controller.

In the `viewDidLoad` method of your `UITabBarController` class (advised to subclass), you set it's `UITabBar`'s items (`UIBarButtonItems`).

Using `UITabBarControllerDelegate`, you can handle their selection. You do not necessarily have to show viewControllers on selection of tabs. You can alter their behaviour by overriding the `shouldSelectViewController:` method.

Problem

Is it not possible to push a UITabBarController inside a UINavigationController? I read back in older versions of iOS but is that still the case now?

Original source