11

I have taken UITabbar on that i have used two buttons as TabItem.I want to perform two different Action by clicking on that two button so how can i get particular Action on clicking on particular Tabbar button.

Ankit Vyas
  • 7,401
  • 13
  • 52
  • 87

2 Answers2

26

You most likely want to take advantage of the UITabBarControllerDelegate, and then handle the didSelectViewController method.

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

See here for more details: http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html

Ben Williams
  • 4,617
  • 7
  • 45
  • 72
25
-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    if(item.tag==1)
    {
        //your code
    }
    else
    {
       //your code
    }
}

You can use UITabBarDelegate for keeping the track of which button is pressed by assigning the tag or title for title you can use item.title.

Pop
  • 11,339
  • 4
  • 50
  • 64
Ahsan
  • 827
  • 6
  • 10
  • This solution is good in a case where you are not using an actual TabBarController and simply want to capture some tab bar tap events in a normal view controller. Thanks! – Ted Avery Dec 14 '12 at 16:11