I want to edit UITabbarItems during the view life time.
The background is that I have an App with login view and according to whether the user is admin or not, the admin TabbarItem should be visible or not.
I’m using this code to initially create the UITabbarController in the AppDelegate:
// AppDelegate.m
settings = [[settingsViewController alloc] init];
settings.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Einstellungen" image:[UIImage imageNamed:@"settings.png"] tag:3];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects:readState, friends, settings, nil];
When I try to manipulate the items later from another UIViewController, nothing happens and the UITabbar remains like it was before.
I actually tried two ways I could imagine:
[[self tabBarController] setToolbarItems:[[[self tabBarController] toolbarItems] arrayByAddingObject:admin] animated:NO];
[[self tabBarController] setViewControllers:[[[self tabBarController] viewControllers] arrayByAddingObject:admin] animated:NO];
How can I reach my goal? Thanks in advance, with kind regards, Julian
I figured out a workaround for my problem. I don’t really like to import the AppDelegate but it seems as the tabbarController property is not being automatically set for the UIViewControllers of a UITabbarController.