user979331
user979331

Reputation: 11841

Remove tab bar item from a UITabBarController scene

I have a storyboard scene that is a UITabBarController scene and it has about 5 tab bar items. What I am trying to do is remove an item or two based on the user's bundle settings. So I created a UITabBarController .h and .m file like so:

.h:

#import <UIKit/UIKit.h>

@interface LHTabBarController : UITabBarController


@end

.h:

#import <Foundation/Foundation.h>
#import "LHTabBarController.h"

@implementation LHTabBarController

-(void)viewDidLoad
{

    /*NSMutableArray *tabbarViewControllers = [NSMutableArray arrayWithArray: [self.tabBarController viewControllers]];
    [tabbarViewControllers removeObjectAtIndex:1];
    [self.tabBarController setViewControllers: tabbarViewControllers];*/

    [super viewDidLoad];

}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [super viewDidAppear:animated];
}

-(void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

@end

and I connected this class to the UITabBarController in my storyboard.

I tried the commented-out code, but that gave me an array saying the array was empty.

How do I remove the tab bar item from this class?

Upvotes: 1

Views: 1204

Answers (1)

Teja Nandamuri
Teja Nandamuri

Reputation: 11201

Simply do this:

As you are doing this on Tab Controller, simply state self than self.tabBarController

 NSArray *actualItems= self.viewControllers;

NSMutableArray *array=[[NSMutableArray alloc]initWithArray:actualItems];
[array removeObjectAtIndex:0];

    [self setViewControllers:array animated:YES];

Upvotes: 5

Related Questions