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
1
vote
0 answers

UITabBar in StoryBoard with 5 buttons. How to go from one to a ViewController that's pushed from a UINavigationController?

I have a Storyboard with one main ViewController. This ViewController is a Tab Bar controller, with 5 buttons. Let's focus on the two first The 1st button does a segue to a UINavigationController. Working fine and shows UIVC1. From here, I can push…
Diego Freniche
  • 5,225
  • 3
  • 32
  • 45
1
vote
2 answers

How to set UITabBarController to View?

I have an app that have several views. In one view I would like to add a UITabBarController. In another app I used this to add the UITabBarController to the rootViewController, but I am not sure if that is even the correct way to do it. in the…
eemceebee
  • 2,656
  • 9
  • 39
  • 49
1
vote
2 answers

How to check user confidencial in a tab based application?

I am building a tab based iphone application, all the information in each tab is user related, which means the user have to login before go to each tab. I put the username/password inputs in the first tab, and I will store the user confidencial in…
scottliyq
  • 107
  • 12
1
vote
1 answer

UITableViewController to UITabBarController's DetailViewController

I have made a XML parser that list correctly in the UITableViewController. It passes a few details and also lat and long for the MKMap view. At first my setup was to go directly from the UITableViewController to the DetailViewController, this worked…
1
vote
3 answers

Displaying Tab bar from second screen in iphone

In delegate class I wrote the code as follows - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions { [self generateFirstScreen]; [self removeFirstScreen]; // On login check implement…
Venkat
  • 343
  • 1
  • 7
  • 17
1
vote
2 answers

How do I have a single shared model for all VCs in a UITabBarController?

I have a UITabBarController, and all the VCs in the tabs use the same model (each tab just displays the model differently). How do I create this model and share it amongst the other VCs? Do I initialize it in the landing VC (when the user opens the…
Tony Stark
  • 24,588
  • 41
  • 96
  • 113
1
vote
2 answers

iOS - Log out of app

I have an app that starts out in the login screen and when you log in it pushes a modal TabBarController. One of the tabs is settings which has a logout button, what would be the correct way to log out of my app and not have any issues such as…
8vius
  • 5,786
  • 14
  • 74
  • 136
1
vote
1 answer

Maintaining state with a TabBarController

I've got a TabBarController, that in it's first instance contains a ViewController for login purposes. After a successful login another viewcontroller is pushed on. I've noticed that if you select the tab again your returned to the top of the…
RubbleFord
  • 7,456
  • 9
  • 50
  • 80
1
vote
0 answers

popToRootViewController without animation crashes

I have a strange problem here. I have a navigation controller set for 2nd tab and if user taps on 1st tab and taps on 2nd tab, then when user taps I am poping to root view controller with out animation. The strange problem I am facing here is if I…
Naveen
  • 636
  • 8
  • 28
1
vote
1 answer

Reload uiview when pressing tab item inside initialized view

I have a view controller inside a tab bar controller. When I'm "inside" the initialized view I want to be able to press the tab bar item again and redraw the view. My tabbarcontroller is created in the AppDelegate #AppDelegate.m -…
1
vote
5 answers

Programatically switching tabs using selectedViewController property

I've used search already, haven't found an answer. Trying to switch like this: [self. tabBarController.selectedViewController OptionsViewContorller]; and like this: [self.tabBarController.selectedViewController =…
Horhe Garcia
  • 882
  • 1
  • 13
  • 28
1
vote
1 answer

iOS/Xcode -- drawRect: Not Being Called in UIView Subclass

I'm working on an app with the main view being a UITabViewController. Under the UITabViewController are three UIViewControllers and one UITableViewController. Under one of the UIViewControllers is a UIView and an NSObject which conforms to…
1
vote
1 answer

Monotouch UITabBarController section showing a modal view

I want to show a modal view when I tap on a section of my UITabBarController or maybe an uipopoverbackgroundview like the one that is included in the GroupMe application. (image included for…
1
vote
0 answers

Button push to specific tab bar item?

I thought this is quite simple but I can't seem to find the answer. I have a view controller with 3 buttons, one of these buttons has a push segue to a tab bar controller. When pressed I presume it loads the '0th' tab item which is the fine for the…
1
vote
1 answer

UITabBarController temporarily missing item title and image in More Navigation Controller

"Has this ever happened to you?" (Note: The following is ARC-friendly code, hence no autorelease call or retain/release pairs.) #pragma mark - UIViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { …
Joe D'Andrea
  • 5,141
  • 6
  • 49
  • 67