从 UITabBarController 场景中移除标签栏项目

Remove tab bar item from a UITabBarController scene

我有一个故事板场景,它是一个 UITabBarController 场景,它有大约 5 个标签栏项目。我想做的是根据用户的捆绑包设置删除一两个项目。所以我创建了一个 UITabBarController .h.m 文件,如下所示:

.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

并且我将此 class 连接到故事板中的 UITabBarController

我尝试了注释掉的代码,但它给了我一个数组,说数组是空的。

如何从此 class 中删除标签栏项目?

只需这样做:

当您在选项卡控制器上执行此操作时,只需声明 self than self.tabBarController

 NSArray *actualItems= self.viewControllers;

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

    [self setViewControllers:array animated:YES];