Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom action when clicking on UITabBarController

I have a Tab Bar Controller with four navigation controllers added to it. The navigation controllers appear as Tab Bar Items in the Tab Bar Controller. Now I want to add a fifth button to the tab bar, that does not open another view, but triggers some custom code. I want to display an overlaying "share menu" when clicking that Tab Bar Item regardless on which of the four pages the user is. How can I do that?

like image 476
priojewo Avatar asked Mar 14 '14 18:03

priojewo


People also ask

What is a tab bar view controller?

A tab bar controller is a powerful UI component for iOS apps. It's a container view, and you use it to group view controllers together. They give your app's user access to the most important screens of your app.

What is the view of the uitabbarcontroller?

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.

Why uitabbarcontroller is a one stop solution in iOS?

A mobile app user wants to see the most useful features of an app at the home page. But we can’t put all of the features on it for the obvious reason of space. To solve this issue and to make it easy for a user to browse through the pages in no time, UITabBarController is a one stop solution in iOS.

How do I associate a Tabbar item with a view controller?

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.

Can You subclass a tab bar controller?

This class is generally used as-is, but may also be subclassed. 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.


1 Answers

I can suggest to add dummy UIViewController to the last index and handle UITabBarControllerDelegate

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {

    if ([viewController == ...your dummy view controller...]) {

        //Your custom action

        return NO;
    }

    return YES;
}
like image 161
Krivoblotsky Avatar answered Sep 26 '22 17:09

Krivoblotsky