János
János

Reputation: 35090

How to change items in UITabBarController

How can I change view controller in UITabBarController. UITabBarController is created from Storyboard. I.e. want to remove last item. Enable to NO UITabBarItem will only disable button, but not hide it.

enter image description here

Upvotes: 1

Views: 351

Answers (1)

isaman kumara
isaman kumara

Reputation: 131

First you need to get viewcontrollers for an array and change the array. After modification assign back to UITabBarController

    NSMutableArray *viewCotrollers = [[NSMutableArray alloc]initWithArray:[tbc viewControllers]];
    [viewCotrollers removeLastObject];
    [tbc setViewControllers:viewCotrollers animated:YES];

To get the TabBarController you can use following code

    UITabBarController *tbc = [[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"tabBarController"];

Todo this you need to set identifier for your UITabBarController on storyboard

Upvotes: 3

Related Questions