use*_*331 1 objective-c uitabbarcontroller ios uistoryboard
我有一个故事板场景,它是一个UITabBarController场景,它有大约 5 个标签栏项目。我想要做的是根据用户的捆绑设置删除一两个项目。所以,我创建了一个UITabBarController .h和.m文件,如下所示:
.h:
#import <UIKit/UIKit.h>
@interface LHTabBarController : UITabBarController
@end
Run Code Online (Sandbox Code Playgroud)
.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
Run Code Online (Sandbox Code Playgroud)
我将这个类连接到UITabBarController我的故事板中。
我尝试了注释掉的代码,但这给了我一个数组,说该数组为空。
如何从这个类中删除标签栏项目?
只需这样做:
当您在 Tab Controller 上执行此操作时,只需声明 self 而非 self.tabBarController
NSArray *actualItems= self.viewControllers;
NSMutableArray *array=[[NSMutableArray alloc]initWithArray:actualItems];
[array removeObjectAtIndex:0];
[self setViewControllers:array animated:YES];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1092 次 |
| 最近记录: |