iOS Developer Library — Pre-Release

Developer

UIKit Framework Reference UITabBarController Class Reference

Options
Deployment Target:

On This Page
Language:

UITabBarController

The UITabBarController class implements a specialized view controller that manages a radio-style selection interface. This tab bar interface displays tabs at the bottom of the window for selecting between the different modes and for displaying the views for that mode. This class is generally used as-is but may be subclassed in iOS 6 and later. More...

Inheritance


Import Statement


Swift

import UIKit

Objective-C

@import UIKit;

Availability


Available in iOS 2.0 and later.
  • delegate delegate Property

    The tab bar controller’s delegate object.

    Declaration

    Swift

    unowned(unsafe) var delegate: UITabBarControllerDelegate?

    Objective-C

    @property(nonatomic, assign) id< UITabBarControllerDelegate > delegate

    Discussion

    You can use the delegate object to track changes to the items in the tab bar and to monitor the selection of tabs. The delegate object you provide should conform to the UITabBarControllerDelegate protocol. The default value for this property is nil.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • tabBar tabBar Property

    The tab bar view associated with this controller. (read-only)

    Declaration

    Swift

    var tabBar: UITabBar { get }

    Objective-C

    @property(nonatomic, readonly) UITabBar *tabBar

    Discussion

    You should never attempt to manipulate the UITabBar object itself stored in this property. If you attempt to do so, the tab bar view throws an exception. To configure the items for your tab bar interface, you should instead assign one or more custom view controllers to the viewControllers property. The tab bar collects the needed tab bar items from the view controllers you specify.

    The tab bar view provided by this property is only for situations where you want to display an action sheet using the showFromTabBar: method of the UIActionSheet class.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 3.0 and later.

  • An array of the root view controllers displayed by the tab bar interface.

    Declaration

    Swift

    var viewControllers: [AnyObject]?

    Objective-C

    @property(nonatomic, copy) NSArray *viewControllers

    Discussion

    The default value of this property is nil. When configuring a tab bar controller, you can use this property to specify the content for each tab of the tab bar interface. The order of the view controllers in the array corresponds to the display order in the tab bar. Thus, the controller at index 0 corresponds to the left-most tab, the controller at index 1 the next tab to the right, and so on. If there are more view controllers than can fit in the tab bar, view controllers at the end of the array are managed by the More navigation controller, which is itself not included in this array.

    If you change the value of this property at runtime, the tab bar controller removes all of the old view controllers before installing the new ones. The tab bar items for the new view controllers are displayed immediately and are not animated into position. When changing the view controllers, the tab bar controller remembers the view controller object that was previously selected and attempts to reselect it. If the selected view controller is no longer present, it attempts to select the view controller at the same index in the array as the previous selection. If that index is invalid, it selects the view controller at index 0.

    Setting this property also sets the customizableViewControllers property to the same set of view controllers.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • Sets the root view controllers of the tab bar controller.

    Declaration

    Swift

    func setViewControllers(_ viewControllers: [AnyObject], animated animated: Bool)

    Objective-C

    - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated

    Parameters

    viewControllers

    The array of custom view controllers to display in the tab bar interface. The order of the view controllers in this array corresponds to the display order in the tab bar, with the controller at index 0 representing the left-most tab, the controller at index 1 the next tab to the right, and so on.

    animated

    If YEStrue, the tab bar items for the view controllers are animated into position. If NOfalse, changes to the tab bar items are reflected immediately.

    Discussion

    When you assign a new set of view controllers at runtime, the tab bar controller removes all of the old view controllers before installing the new ones. When changing the view controllers, the tab bar controller remembers the view controller object that was previously selected and attempts to reselect it. If the selected view controller is no longer present, it attempts to select the view controller at the same index in the array as the previous selection. If that index is invalid, it selects the view controller at index 0.

    This method also sets the value of the customizableViewControllers property to the contents of the viewControllers parameter.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    viewControllers

  • The subset of view controllers managed by this tab bar controller that can be customized.

    Declaration

    Swift

    var customizableViewControllers: [AnyObject]?

    Objective-C

    @property(nonatomic, copy) NSArray *customizableViewControllers

    Discussion

    This property controls which items in the tab bar can be rearranged by the user. When the user taps the More item on the tab bar view, a custom interface appears displaying any items that did not fit on the main tab bar. This interface also contains an Edit button that allows the user to rearrange the items. Only the items whose associated view controllers are in this array can be rearranged from this interface. If the array is empty or the value of this property is nil, the tab bar does not allow any items to be rearranged.

    Changing the value of the viewControllers property (either directly or using the setViewControllers:animated: method) also changes the value of this property. When first assigned to the tab bar controller, all view controllers are customizable by default.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The view controller that manages the More navigation interface. (read-only)

    Declaration

    Swift

    var moreNavigationController: UINavigationController { get }

    Objective-C

    @property(nonatomic, readonly) UINavigationController *moreNavigationController

    Discussion

    This property always contains a valid More navigation controller, even if a More button is not displayed on the screen. You can use the value of this property to select the More navigation controller in the tab bar interface or to compare it against the currently selected view controller.

    Do not add the object stored in this property to your tab bar interface manually. The More controller is displayed automatically by the tab bar controller as it is needed. You must also not look for the More navigation controller in the array of view controllers stored in the viewControllers property. The tab bar controller does not include the More navigation controller in that array of objects.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

  • The view controller associated with the currently selected tab item.

    Declaration

    Swift

    unowned(unsafe) var selectedViewController: UIViewController?

    Objective-C

    @property(nonatomic, assign) UIViewController *selectedViewController

    Discussion

    This view controller is the one whose custom view is currently displayed by the tab bar interface. The specified view controller must be in the viewControllers array. Assigning a new view controller to this property changes the currently displayed view and also selects an appropriate tab in the tab bar. Changing the view controller also updates the selectedIndex property accordingly. The default value of this property is nil.

    In iOS 3.0 and later, you can use this property to select any of the view controllers in the viewControllers property. This includes view controllers that are managed by the More navigation controller and whose tab bar items are not visible in the tab bar. You can also use it to select the More navigation controller itself, which is available from the moreNavigationController property. Prior to iOS 3.0, you could select only the More navigation controller and the subset of view controllers whose tab bar item was visible. Attempting to set this property to a view controller whose tab bar item was not visible had no effect.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.

    See Also

    selectedIndex

  • The index of the view controller associated with the currently selected tab item.

    Declaration

    Swift

    var selectedIndex: Int

    Objective-C

    @property(nonatomic) NSUInteger selectedIndex

    Discussion

    This property nominally represents an index into the array of the viewControllers property. However, if the selected view controller is currently the More navigation controller, this property contains the value NSNotFound. Setting this property changes the selected view controller to the one at the designated index in the viewControllers array. To select the More navigation controller itself, you must change the value of the selectedViewController property instead.

    In versions of iOS prior to version 3.0, this property reflects the index of the selected tab bar item only. Attempting to set this value to an index of a view controller that is not visible in the tab bar, but is instead managed by the More navigation controller, has no effect.

    Import Statement

    Swift

    import UIKit

    Availability

    Available in iOS 2.0 and later.