gpt4 book ai didi

iphone - 以编程方式设置 UITabBar 标题

转载 作者:行者123 更新时间:2023-11-29 11:22:47 25 4
gpt4 key购买 nike

我已经以编程方式添加了标签栏,如下所示:-

FirstViewController *obj_FirstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; SecondViewController *obj_SecondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; ThirdViewController *obj_ThirdViewController = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil];

navigation1 = [[UINavigationController alloc] initWithRootViewController:obj_FirstViewController];
navigation2 = [[UINavigationController alloc] initWithRootViewController:obj_SecondViewController];
navigation3 = [[UINavigationController alloc] initWithRootViewController:obj_ThirdViewController];

MainTabBar = [[UITabBarController alloc] init];
MainTabBar.delegate=self;
[MainTabBar setViewControllers:[NSArray arrayWithObjects:navigation1,navigation2,navigation3,nil]];
MainTabBar.view.frame=self.view.frame;
MainTabBar.selectedIndex=0;
[self.view addSubview:MainTabBar.view]

通过在 (void)viewDidLoad 中编写此代码,我在 viewcontroller 中获得了 3 选项卡。但问题是我想将选项卡的名称设置为 1)Home 2)Favorites 3)About us

我曾尝试编写以下代码:

- 1)obj_FirstViewController.tabBarItem.title=@"Home"; 2)self.title = @"My View Controller";

但这行不通。任何人都可以帮助我如何以编程方式执行此操作。在哪里写这行,以便我在我的标签栏中得到这 3 个名字

最佳答案

试试这种方式...

NSMutableArray *controllers = [[NSMutableArray alloc] init];
FirstViewController *obj_FirstViewController = [[FirstViewController alloc] init];
[obj_FirstViewController setTitle:@"first"];
UITabBarItem *item = [[[UITabBarItem alloc] setTabBarItem: [[[UITabBarItem alloc] initWithTitle: @"First") image:[UIImage imageNamed:@"first.png"] tag:2] autorelease]];
[obj_FirstViewController setTabBarItem:item];
[controllers addObject:obj_FirstViewController];
[obj_FirstViewController release];

关于iphone - 以编程方式设置 UITabBar 标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6056354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com