Sets the root view controllers of the tab bar controller.
SDKs
- iOS 2.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
Framework
- UIKit
Declaration
- (void)setViewControllers:(NSArray<_ _kindof UIView Controller *> *)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
YES
, the tab bar items for the view controllers are animated into position. IfNO
, 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 customizable
property to the contents of the view
parameter.