views:

310

answers:

1

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.

+1  A: 

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.

Steve Finkelstein
How can I access window from a UIViewController?
Sheehan Alam
[[UIApplication sharedApplication] keyWindow]. If you have several windows then you'll need to use [[UIApplication sharedApplication] windows].
Steve Finkelstein