Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a good UITabBarController Example?

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.

like image 260
Sheehan Alam Avatar asked Jun 10 '10 02:06

Sheehan Alam


People also ask

What is a UITabBarController?

A container view controller that manages a multiselection interface, where the selection determines which child view controller to display.

When should you use a tab bar controller?

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.

What is a UIViewController?

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.

How do I add a tab bar to my navigation controller?

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.


2 Answers

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.

like image 122
randombits Avatar answered Sep 25 '22 20:09

randombits


Here's one implementation of UITabBarController initialized in a UIViewController.

The author also posted a github link to the xcode project.

like image 43
haifacarina Avatar answered Sep 25 '22 20:09

haifacarina