【问题标题】:Remove tab bar item from a UITabBarController scene从 UITabBarController 场景中删除标签栏项目
【发布时间】:2015-12-22 10:34:44
【问题描述】:

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

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

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

【问题讨论】:

    标签: ios objective-c uitabbarcontroller uistoryboard


    【解决方案1】:

    只需这样做:

    当您在 Tab Controller 上执行此操作时,只需声明 self 而不是 self.tabBarController

     NSArray *actualItems= self.viewControllers;
    
    NSMutableArray *array=[[NSMutableArray alloc]initWithArray:actualItems];
    [array removeObjectAtIndex:0];
    
        [self setViewControllers:array animated:YES];
    

    【讨论】:

    • 错误No visible @interface for 'NSArray' declares the selector 'removeObjectAtIndex:'
    • NSArray 不是可编辑数组。您必须使其可变,然后删除不需要的对象
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 2017-12-22
    • 1970-01-01
    相关资源
    最近更新 更多