Is there a good UITabBarController example where it is NOT created in the appDelegate?
I would like to use a UITabBarController inside of a UIViewController, however dont know how to set the view outlet.
A container view controller that manages a multiselection interface, where the selection determines which child view controller to display.
They can be used to allow the user to navigate between entirely different parts of your application, or they can be used to display two different views of the same backing data. Tab bar controllers also have the built-in ability to display a "More..." interface when more than 5 tabs are added.
The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.
To add a tab, first drag a new View Controller object to the storybard. Next control-drag from the tab bar controller to new view controller and select view controllers under Relationship Segue . Your tab bar controller will update with a new tab.
This is all very well documented here. It shouldn't matter where the UITabBarController instance is created, UIApplicationDelegate or not. In a nutshell, Create all of your respective UIViewController's and add them to an array. Then assign that array to your UITabBarController's viewControllers property. Then you can simply do something like [window addSubview:myTabBarController.view]
.
I'm just copy/pasting from the documentation here:
You should never access the tab bar view of a tab bar controller directly. To configure the tabs of a tab bar controller, you assign the view controllers that provide the root view for each tab to the viewControllers property. The order in which you specify the view controllers determines the order in which they appear in the tab bar. When setting this property, you should also assign a value to the selectedViewController property to indicate which view controller is selected initially. (You can also select view controllers by array index using the selectedIndex property.) When you embed the tab bar controller’s view (obtained using the inherited view property) in your application window, the tab bar controller automatically selects that view controller and displays its contents, resizing them as needed to fit the tab bar interface.
Here's one implementation of UITabBarController initialized in a UIViewController.
The author also posted a github link to the xcode project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With