简体   繁体   English

标签栏项目标题以编程方式未显示在目标 c 中

[英]tab bar item title programatically not showing in objective c

I try create tab bar controller programatically, it works but I can not set title to ta bar items.我尝试以编程方式创建标签栏控制器,它可以工作,但我无法将标题设置为标签栏项目。 I can not see title when I running my application.运行应用程序时看不到标题。 My code is here.我的代码在这里。 Please help me, what is the problem?请帮帮我,是什么问题?

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.

myTabBarController = [[UITabBarController alloc] init];        
view2Controller = [[testView alloc] init];   
view3Controller = [[testView2 alloc] init];   
view4Controller = [[testView3 alloc] init];   
view5Controller = [[testView4 alloc] init];   
view6Controller = [[testView5 alloc] init];   


myTabBarController.viewControllers = [NSArray arrayWithObjects: view2Controller, view3Controller,view4Controller,view5Controller,view6Controller,nil]; 
 UITabBarItem *tabItem = [[[myTabBarController tabBar] items] objectAtIndex:1];
 [tabItem setTitle:@"theTitle"];

[self.view addSubview:myTabBarController.view];    
myTabBarController.selectedIndex=0;

}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

        // self.title = @"My Title";
    }

    self.title = @"My Title";
    return self;
}

Use above code in every subviews of tabbar controllers.在 tabbar 控制器的每个子视图中使用上面的代码。

This may be help.这可能有帮助。

use this code

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.title=@"FREE BOOKS";
        self.tabBarItem.image = [UIImage imageNamed:@"first"];
    }
    return self;
}

在侧视图控制器的 viewwillappear/disappear 中设置你的 viewcontroller 的标题,它将显示在你的 tabbaritem 中。

You can set the title of UIViewController , which reflects when it is pushed in UINavigationController or a UITabBarController .您可以设置UIViewController的标题,这反映了它何时被推送到UINavigationControllerUITabBarController But you should set the title before putting it inside any of them.但是您应该在将其放入其中任何一个之前设置标题。

init is generally a good place to set the title. init通常是设置标题的好地方。

- (id)init {
    // ... other code including check for self
    self.title = @"My Title";
    return self;
}
override func viewDidLoad() {
    super.viewDidLoad()

    DispatchQueue.main.async {
        self.tabBar.items?[0].title = "Title"
    }

}

OR要么

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.tabBar.items?[0].title = "Title"

}

Here is the tutorial from the scratch which should help you to achieve the exact functionality you want to achieve. 是从头开始的教程,它应该可以帮助您实现您想要实现的确切功能。 Download the source code and run it directly and if title are correct the you can follow the tutorial to get the proper understanding of the flow of UITabBarController.下载源码直接运行,如果标题正确,可以按照教程正确理解UITabBarController的流程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在启动时以编程方式为5个选项卡栏项目设置选项卡栏标题,其中4个选项卡嵌入在Navigation Controller中,而1个则没有。 目标C - Set Tab Bar title programatically at Startup for 5 Tab Bar item, 4 of which is embedded in Navigation Controller, 1 is not. Objective C 如何在目标c中以编程方式设置标签栏项目标题? - How to set tab bar item title programmatically in objective c? iPhone Objective-C:以编程方式更改使用IB创建的标签栏中标签栏项目的标题? - iPhone Objective-C: Programmatically change title of tab bar item in tab bar created using IB? Objective-C:选项卡栏项目的标题在登录页面后不会更改,但是从xCode重新启动时可以使用吗? - Objective-C : Title of tab bar item will not change after login page but works when relaunch from xCode? Objective C 标题栏 - Objective c title Bar 在应用程序上全局更改选项卡栏标题。委托Objective C - Change the Tab Bar title globally at apps.Delegate Objective C 标签栏项目的标题未显示 - Title of tab bar items not showing 如何在目标c中设置Tab栏项badgeValue? - How to set Tab bar item badgeValue in objective c? 目标C添加一个选项卡栏项以更改为其他视图 - Objective C adding a tab bar item to change to other views 单击选项卡栏项,然后在Objective-c中执行方法 - Click on a tab bar item and execute a method in Objective-c
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM