[英]Remove tab bar item from a UITabBarController scene
我有一个Storyboard场景,它是一个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
。
我尝试了注释掉的代码,但这给了我一个数组,说该数组为空。
如何从此类中删除选项卡栏项?
只需执行以下操作:
在Tab控制器上执行此操作时,只需声明self而不是self.tabBarController
NSArray *actualItems= self.viewControllers;
NSMutableArray *array=[[NSMutableArray alloc]initWithArray:actualItems];
[array removeObjectAtIndex:0];
[self setViewControllers:array animated:YES];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.