views:

1149

answers:

3

UIActionSheet has a showFromTabBar: method

- (void)showFromTabBar:(UITabBar *)view

But how to get a reference to the UITabBar?

I'm currently using

UITabBar *tabBar = [self.tabBarController.view.subviews objectAtIndex:0];

I've also seen someone traversing tabBarController.view.subviews and looking for the UITabBar instance. Is there a better way to do this?

A: 

If you are using interface-builder you can define something like this as a member in your class interface:

IBOutlet UITabBar* tabbar;

And connect this outlet to the UITabBar via interface-builder (the UITabBar should be inside the tabBar controller when viewing the xib document window in tree-view mode). Then just use this tabbar member to reference it in your code.

Mike Weller
+2  A: 

You can use

UITabBar *tabBar = self.tabBarController.tabBar;
Rafael Vega
A: 

This seems to not work any longer in the iPhone OS 3.x... I get errors. Of course, it may be what I'm trying to do next, which is disable one of the tabbar items...

UITabBarItem *tabBarItem = [[tabBar items] objectAtIndex:2];

[tabBarItem setEnabled:FALSE];

Apple's documentation suggests you have to jump through more hoops to access tab bar -- going through delegate...