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
42
votes
11 answers

How to get the previous viewcontroller that pushed my current view

The home page of my app has UIButtons, btnIncome and btnExpense. Pressing on this buttons pushes IncomeVC and ExpenseVC respectevely,which are two UIViewControllers with UITabBar added via xib. The tabBar have 4 items. Selecting on each tab item…
40
votes
11 answers

Getting the frame of a particular tab bar item

Is there a way to find the frame of a particular UITabBarItem in a UITabBar? Specifically, I want to create an animation of an image "falling" into one of the tabs, similar to e.g. deleting an email in the Mail, or buying a track in the iTunes app. …
Daniel Dickison
  • 21,832
  • 13
  • 69
  • 89
39
votes
2 answers

viewWillAppear, viewDidAppear not being called, not firing

(This is both question and answer since it took quite a bit of digging to find the real answer.) Symptom: viewWillAppear, viewDidAppear were not being called in my UIViewController. Cause: Embedding a UINavigationController or UITabBarController…
pschang
  • 2,568
  • 3
  • 28
  • 23
39
votes
7 answers

Changing font in UITabBarItem

Hi I have this code and it doesn't work, what am I doing wrong? - (void)viewDidLoad { [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"AmericanTypewriter" size:20.0f],…
user1457381
38
votes
7 answers

Change tab name in uitabbarcontroller

I have a TabBarController set as main controller tab, where names were defined using interface builder. Now I would like to change its names programmatically. How could it be done?
Ruth85
  • 645
  • 2
  • 7
  • 12
37
votes
10 answers

How to set tab bar item title programmatically in objective c?

I want to set title to tab item programatically, but it not works. My code is below: - (IBAction)tab1Click:(id)sender { myTabBarController = [[UITabBarController alloc] init]; view2Controller = [[View2Controller alloc] init]; …
Hacer sengul Akac
  • 683
  • 3
  • 17
  • 25
37
votes
7 answers

Reordering view controllers in a UITabBarController, all defined in a Storyboard

I'd like to change the order of view controllers attached to a UITabBarController, within my Storyboard, without disconnecting all view controllers and reconnecting them in the desired order. My Question: Can this be done just via the Storyboard IB…
idStar
  • 10,674
  • 9
  • 54
  • 57
36
votes
14 answers

Tap tab bar to scroll to top of UITableViewController

Tapping the tab bar icon for the current navigation controller already returns the user to the root view, but if they are scrolled way down, if they tap it again I want it to scroll to the top (same effect as tapping the status bar). How would I do…
35
votes
9 answers

Hiding UITabBar when pushing a UIView

I have a UITabBarController where the default view controller is a UINavigationController. I want to be able to hide the UITabBar of the UITabBarController when I push a certain view in the UINavigationController. I've tried…
Benny Wong
  • 6,773
  • 5
  • 31
  • 25
35
votes
5 answers

Prevent automatic popToRootViewController on double-tap of UITabBarController

The default behavior of a UITabBarController is to pop the contained UINavigationController to the root view controller when a particular tab is tapped a second time. I have a particular use case where I'm wanting this to not work automatically, and…
Ecton
  • 10,702
  • 2
  • 35
  • 44
34
votes
7 answers

Programmatically setting tabBarItem title in Swift

I have four UIViewControllers that are linked to a UITabBarController's tab bar. I need to set the tab bar item titles outside of the storyboard, and inside of their classes. I've tried.. class MyViewController: UIViewController { required…
Sam
  • 1,042
  • 2
  • 8
  • 19
34
votes
16 answers

Iphone: Is it possible to hide the TabBar? (Pre-iOS 8)

I have an application that uses a UITabBarController to switch between modes. When in a certain mode, I'd like to hide the tab bar until the steps of that mode have been completed. Note that I'm not using a navigation controller so I can't use the…
Steve
  • 2,678
  • 8
  • 40
  • 54
32
votes
8 answers

How to hide parent tabbar when pushing controller in navigationController

I have an application with a tab bar controller and each view contains a navigation controller. My MainWindow looks as follows: Image here http://www.freeimagehosting.net/image.php?7bc867a594.png Everything works fine as it is but I noticed a…
Yannis
  • 6,047
  • 5
  • 43
  • 62
31
votes
1 answer

UITabBarController is possible to select the tab via code?

is it UITabBarController possible to select the tab in code?like UINavigationController we can use popViewController pop back to rootViewController instead of press the back button, so how can this implement in tabbarcontroller?
ronny
31
votes
9 answers

hidesBottomBarWhenPushed = NO not working?

I have a UITabBar in my app, which I'm hiding on the first UIViewController in the first tab by putting this line in the AppDelegate: // ... in MyAppDelegate.m firstViewController.hidesBottomBarWhenPushed = YES; In the firstViewController, the user…
rottendevice
  • 2,849
  • 6
  • 30
  • 37