views:

330

answers:

2

Hi there,

i'm searching for a way to disable a TabBarItem from within the ViewController of one of the TabBars Tabs. I'm even not sure if this is about the View Hierarchy or what to really search for. I tried a lot but didn't come up with a solution.

Right now I worked arround it by saving a reference to the tabbar in a singelton object when instanciating the tabbar (inside the apps delegate). But I don't think this is the best way to do it.

Thanks and Cheers, Nils

A: 

Hi Nils,

Maybe I don't understand what you are wanting, but I have dissabled a tab bar button by going into interface builder, then selecting the tab button i want to work on (small blue highlight color only on the place holder for the picture, the small box with a ? on it) then -> Tools Menu -> Inspector -> Tab Bar Item Properties (first tab on left in the Inspector) -> then a small radio button on the bottom says "Enabled" -> deselect this. Works for me, as I use this as a simple load screen on the first tab. Hope that helps. Kirk

Digiguy
A: 

Hi, I had the same problem and I have found a solution (but I find it a little bit dirty)

In your ViewController where you want to disable the TabBarItem, create a variable : UITabBarController *myTabBarController; with property ....

In the class where you manage your Tabbarcontroller put this code in the viewDidLoad : MyViewController * vc = (MyViewController *)[navigationController.viewControllers objectAtIndex:0];// O the index of the first view controller replace it with the index of the needed viewController

vc.myTabBarController = myTabBarController; // pass your TabBarController to your ViewController

Now back to your ViewController class (MyViewController) and use this code to desable the tabBarItem : UITabBarItem *mapTabBarItem= [[myTabBarController.tabBar items] objectAtIndex:1]; // I want to desable the second tab for example (index 1)

[mapTabBarItem setEnabled:NO];

Note that this is not the best way to do it, but it works :-)

Evane