从UITabBarController场景中删除选项卡栏项

时间:2015-09-24 17:52:47

标签: ios objective-c uitabbarcontroller uistoryboard

我有一个故事板场景是一个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

我将此课程连接到我的故事板中的UITabBarController

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

如何从此课程中删除标签栏项?

1 个答案:

答案 0 :(得分:4)

只需这样做:

正如您在Tab Controller上所做的那样,只需声明self而不是self.tabBarController

 NSArray *actualItems= self.viewControllers;

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

    [self setViewControllers:array animated:YES];