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
31
votes
5 answers

How to animate Tab bar tab switch with a CrossDissolve slide transition?

I'm trying to create a transition effect on a UITabBarController somewhat similar to the Facebook app. I managed to get a "scrolling effect" working on tab switch, but I can't seem to figure out how to cross dissolve (or it doesn't work at…
JoniVR
  • 1,839
  • 1
  • 22
  • 36
31
votes
6 answers

UITabBar(Controller) - Get index of tapped?

I've got a tab bar application and I need to know when and what button a user taps on the tab bar as to display the appropriate notifications and such. In short: How would I go about detecting the index of a tapped UITabBarItem on a UITabBar? Thanks…
esqew
  • 42,425
  • 27
  • 92
  • 132
31
votes
3 answers

iOS Tab Bar icons keep getting larger

I am having a problem with my icons in my tabBar. Tapping the same tab bar button repeatedly will keep increasing the tab bar icon's size. If I push a different one, it goes back to its original size. Any ideas what I should fix?
31
votes
5 answers

how to get the event that switch tab menu on iphone

I'm trying to figure out how to catch the event that controls the switch tabs on the UITabBarController. How could I accomplish this?
Yan
  • 1,424
  • 4
  • 21
  • 44
31
votes
10 answers

Tab Bar covers TableView cells in iOS7

I have a custom tableViewController that I'm adding to a TabBarController with self.tabBarController.viewControllers = [NSArray arrayWithObjects:someOtherViewController, customTableViewController, nil]; self.tabBarController.selectedIndex = 1; The…
JuJoDi
  • 14,627
  • 23
  • 80
  • 126
29
votes
5 answers

How to hide the tabBar when push a view?

My application is a Tabbed Application, and it have several controllers under the tabBarController. One controller is a navigationController, and its root view is a table view. When I click a row of the table view, another view will be pushed in.…
wjldxt
  • 345
  • 1
  • 3
  • 5
29
votes
10 answers

spacing between UITableViewCells

I am creating a ios app in swift and want to add spacing between cells like Facebook (pic bellow). I am using a custom nib for the posts. I know to use UITableViewController. I figure I would use a separator style but it does not achieve the effect.…
Now2407
  • 469
  • 1
  • 5
  • 11
29
votes
10 answers

How do I hide/show tabBar when tapped using Swift in iOS8

I am trying to mimic the UINavigationController's new hidesBarsOnTap with a tab bar. I have seen many answers to this that either point to setting the hidesBottomBarWhenPushed on a viewController which only hides it entirely and not when tapped. …
Michael Campsall
  • 4,325
  • 11
  • 37
  • 52
29
votes
7 answers

hide tab bar in view with push

I have a tabBar + NavigationViewController. The Tab bar has collection view with cells(Say view1) and with cells a push seague is implemented to another view(Say view2). In view2 I want to have a navBar but no tab bar. I tried…
29
votes
11 answers

How can I change the text and icon colors for tabBarItems in iOS 7?

How can I change the text and icon colors for UITabBar and UITabBarItems in iOS 7? The default gray text seems dim and hard to read for unselected tabbar items.
Ed Fernandez
  • 1,823
  • 2
  • 14
  • 18
28
votes
5 answers

Unbalanced calls to begin/end appearance transitions for UITabBarController

I have an UITabBarController, when initial run, I want to overlay a login view controller but received error. Unbalanced calls to begin/end appearance transitions for < UITabBarController: 0x863ae00 >. Below is the code. -…
ZYiOS
  • 5,204
  • 3
  • 39
  • 45
28
votes
6 answers

Swift: How to execute an action when UITabBarItem is pressed

Currently I have a Tab Bar Controller that is connected to a tableview controller. I'm trying to go to the top of the tableview when I press the tab bar item. I know how to get to the top of the tableview. I just don't know how to do an action when…
K Swisha
  • 303
  • 1
  • 3
  • 6
28
votes
9 answers

UISplitViewController in a TabBar ( UITabBarController )?

I am in kind of situation that I need to start with a tab based application and in that I need a split view for one or more tabs. But it seems that split view controller object can not be added to the tabbarController. (Although tabbar object can be…
27
votes
6 answers

How to change the Color of text in UITabBarItem in iOS 5

with more appearance control in iOS 5, how do we change the UITabBarItem text color ? from default white to other color ? EDIT:working solution [[UITabBarItem appearance] setTitleTextAttributes: [NSDictionary…
Desmond
  • 5,001
  • 14
  • 56
  • 115
27
votes
2 answers

How do i use coordinators with a UIITabBarController?

I'm playing around with the MVVM-C architecture, but i'm unsure how i can instantiate multiple coordinators with different tabs when a tab is selected. Here's my main app coordinator class... protocol UINavigationControllerType: class { func…
Luke97
  • 529
  • 3
  • 11
  • 27