Questions tagged [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.

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.

Each tab of a tab bar controller interface is associated with a custom view controller. When the user selects a specific tab, the tab bar controller displays the root view of the corresponding view controller, replacing any previous views. (User taps always display the root view of the tab, regardless of which tab was previously selected. This is true even if the tab was already selected.) Because selecting a tab replaces the contents of the interface, the type of interface managed in each tab need not be similar in any way. In fact, tab bar interfaces are commonly used either to present different types of information or to present the same information using a completely different style of interface. Figure 1 shows the tab bar interface presented by the Clock application, each tab of which presents a type of time based information.

enter image description 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.

Tab bar items are configured through their corresponding view controller. To associate a tab bar item with a view controller, create a new instance of the UITabBarItem class, configure it appropriately for the view controller, and assign it to the view controller’s tabBarItem property. If you do not provide a custom tab bar item for your view controller, the view controller creates a default item containing no image and the text from the view controller’s title property.

As the user interacts with a tab bar interface, the tab bar controller object sends notifications about the interactions to its delegate. The delegate can be any object you specify but must conform to the UITabBarControllerDelegate protocol. You can use the delegate to prevent specific tab bar items from being selected and to perform additional tasks when tabs are selected. You can also use the delegate to monitor changes to the tab bar that are made by the More navigation controller, which is described in more detail in The More Navigation Controller.

For more information about using tab bar controllers to build your user interface, see View Controller Programming Guide for iOS.

The Views of a Tab Bar Controller

Because the UITabBarController class inherits from the UIViewController class, tab bar controllers have their own view that is accessible through the view property. The view for a tab bar controller is just a container for a tab bar view and the view containing your custom content. The tab bar view provides the selection controls for the user and consists of one or more tab bar items. Figure 2 shows how these views are assembled to present the overall tab bar interface. Although the items in the tab bar and toolbar views can change, the views that manage them do not. Only the custom content view changes to reflect the view controller for the currently selected tab.

enter image description here

The More Navigation Controller

The tab bar has limited space for displaying your custom items. If you add six or more custom view controllers to a tab bar controller, the tab bar controller displays only the first four items plus the standard More item on the tab bar. Tapping the More item brings up a standard interface for selecting the remaining items.

The interface for the standard More item includes an Edit button that allows the user to reconfigure the tab bar. By default, the user is allowed to rearrange all items on the tab bar. If you do not want the user to modify some items, though, you can remove the appropriate view controllers from the array in the customizableViewControllers property.

State Preservation

In iOS 6 and later, if you assign a value to this view controller’s restorationIdentifier property, it preserves a reference to the view controller in the selected tab. At restore time, it uses the reference to select the tab with the same view controller.

When preserving a tab bar controller, assign unique restoration identifiers to the child view controllers you want to preserve. Omitting a restoration identifier from a child view controller causes that tab to return to its default configuration. Although the tab bar controller saves its tabs in the same order that they are listed in the viewControllers property, the save order is actually irrelevant. Your code is responsible for providing the new tab bar controller during the next launch cycle, so your code can adjust the order of the tabs as needed. The state preservation system restores the contents of each tab based on the assigned restoration identifier, not based on the position of the tab.

For more information about how state preservation and restoration works, see App Programming Guide for iOS.

6522 questions
173
votes
12 answers

Switching to a TabBar tab view programmatically?

Let's say I have a UIButton in one tab view in my iPhone app, and I want to have it open a different tab in the tab bar of the TabBarController. How would I write the code to do this? I'm assuming I unload the existing view and load a specific…
rottendevice
  • 2,849
  • 6
  • 30
  • 37
132
votes
24 answers

Unbalanced calls to begin/end appearance transitions for

I read SO about another user encountering similar error, but this error is in different case. I received this message when I added a View Controller initially: Unbalanced calls to begin/end appearance transitions for
Raptor
  • 53,206
  • 45
  • 230
  • 366
120
votes
9 answers

how to change uiviewcontroller title independent of tabbar item title

I am setting my view controllers title like this in view did load: self.title = @"my title"; prior to this I set the title in story boards for the view controller and navigation controller it is embedded in. I set it to: "Title"; When I click on…
Atma
  • 29,141
  • 56
  • 198
  • 299
108
votes
20 answers

iPhone: How to switch tabs with an animation?

I'm switching tabs programmatically in a tab bar driven application using UITabBarController.selectedIndex. The problem I'm trying to solve is how to animate the transition between the views. ie. from the view of the current tab to the view of the…
drekka
  • 20,957
  • 14
  • 79
  • 135
101
votes
6 answers

What size should TabBar images be?

I have icons for a tabBar of size 100. I checked at Apple's Human Interface Guidelines of 2013 and it says the image size should be 30x30 / 60x60. But as the height of tab bar controller is 50, I kept the size of the image at 50x50. Now, when I run…
Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276
95
votes
12 answers

Programmatically switching between tabs within Swift

I need write some code to switch the view to another tab when the iOS app starts (so, for example, the second tab is shown by default rather than the first). I'm new to Swift, and have worked out the following: The code should probably go in the…
Oliver Spencer
  • 2,021
  • 3
  • 16
  • 22
94
votes
13 answers

Determine if UIView is visible to the user?

is it possible to determine whether my UIView is visible to the user or not? My View is added as subview several times into a Tab Bar Controller. Each instance of this view has a NSTimer that updates the view. However I don't want to update a view…
jantimon
  • 36,840
  • 23
  • 122
  • 185
87
votes
18 answers

Changing Tint / Background color of UITabBar

The UINavigationBar and UISearchBar both have a tintColor property that allows you to change the tint color (surprising, I know) of both of those items. I want to do the same thing to the UITabBar in my application, but have found now way to change…
pixel
  • 5,298
  • 8
  • 35
  • 32
82
votes
17 answers

iOS 15 UITabBarController's tabBar background color turns black

tabBar.barTintColor can't be changed in iOS 15 beta 4. Background. We have an app in App Store and each year before the new iOS major version releases we download the iOS beta and test our app to fix the issues beforehand. Our problem. This year…
Zhengqian Kuang
  • 1,079
  • 1
  • 9
  • 12
80
votes
9 answers

Tab bar controller inside a navigation controller, or sharing a navigation root view

I'm trying to implement a UI structured like in the Tweetie app, which behaves as so: the top-level view controller seems to be a navigation controller, whose root view is an "Accounts" table view. If you click on any account, it goes to the second…
Daniel Dickison
  • 21,832
  • 13
  • 69
  • 89
76
votes
16 answers

How to hide uitabbarcontroller

I have a problem with UITabBarController. In my application, I want to hide it but without using hidesBottomBarWhenPushed because I want to hide it not when I pushed it. For Example, I want to hide it when I press a Hide button in my application. I…
Viktor Apoyan
  • 10,655
  • 22
  • 85
  • 147
76
votes
7 answers

Adding new tabs to a tab bar controller

I am creating a tab bar iOS app. The tab bar view controller has two tabs, each of them connected to a view controller. This how it looks: I need to add more tabs to the tab controller. I am doing it at the storyboard as follows: I add a new view…
mvasco
  • 4,965
  • 7
  • 59
  • 120
76
votes
24 answers

Change UITabBar height

I use UITabBarController as a root view and app supports iOS 6 and above. Project class hierarchy is as below. UITabBarController - tab1 - UINavigationController - UIViewController - UIViewController . . - tab2 -…
Geek
  • 8,280
  • 17
  • 73
  • 137
70
votes
6 answers

Detect when a tab bar item is pressed

I have a root view controller which isn’t set as the custom class for any of my view controllers on my storyboard. Instead, all of my view controllers are subclassing this class like so. // RootViewController class RootViewController:…
Tunds
  • 1,804
  • 2
  • 15
  • 30
69
votes
15 answers

How to hide tab bar with animation in iOS?

So I have a button that is connected to a IBAction. When I press the button I want to hide the tab bar in my iOS app with a animation. This [self setTabBarHidden:hidden animated:NO]; or this [self.tabBarController setTabBarHidden:hidden…
b3rge
  • 4,959
  • 7
  • 23
  • 24
1
2 3
99 100