0

I am trying to find a way to make an item of the TabBar acting as a "UIbutton". I would like when pressing to this item just make it work as a ibaction method.

I tried several implementation as :

   -(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item{
   }

But I was not able to get the method working.

What will be the best solution to fake an item function of a tabbar, and make it open an UIActionSheet for example ?

Ben
  • 1,031
  • 3
  • 17
  • 31

4 Answers4

1

Try using an IBOutlet and UITabBarDelegate in your viewController.

@interface MyViewController : UIViewController <UITabBarDelegate> {
  IBOutlet UITabBar* tabBar;
}
@end

Connect the UITabBar to that IBOutlet in Interface Builder.

Set the delegate to 'self' in your viewController's viewDidLoad method:

-(void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.
  tabBar.delegate = self;
}

And set up the delegate method with some way to differentiate the tabs:

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
  NSLog(item.title);
  if([item.title isEqualToString:@"some label"]) {
     // do something for this specific button
  }
}

(This is an old post, but I had the same question. Hopefully this saves someone else the same trouble.)

fith
  • 101
  • 5
0

You can try the tabBarController shouldSelectViewController delegate method. Override this. Return NO on the tab you want to display an ActionSheet from, and instead instantiate the ActionSheet in this method.

You'll be required to have a placeholder UIViewController in place of this tab.

As mentioned above, this goes against Apple HIG and might be reason for your app to be rejected.

CSmith
  • 13,318
  • 3
  • 39
  • 42
0

Check this out! These people create a tabBar with a uibutton in it! http://idevrecipes.com/2010/12/16/raised-center-tab-bar-button/

Full source code: https://github.com/boctor/idev-recipes/tree/master/RaisedCenterTabBar

I tried the code some time ago and it worked for me.

The dude
  • 7,896
  • 1
  • 25
  • 50
-1

Call your action method in the viewDidLoad method of the view of the tab bar item selected.

Ravi
  • 7,929
  • 6
  • 38
  • 48