gpt4 book ai didi

ios - 代码中的 UITabBarController 不显示导航栏

转载 作者:行者123 更新时间:2023-11-28 23:27:18 25 4
gpt4 key购买 nike

我们使用 Storyboard在 Obj C 代码中创建了一个 UITabBarController。它工作正常,但是导航栏不会显示在任何 View 上。尝试过在 TabBarController 中创建导航栏和其他一些东西。大多数示例不显示导航栏...任何具体的代码示例将不胜感激,谢谢!这是 VDL 代码:

- (void)viewDidLoad {
[super viewDidLoad];

UITabBarItem * startTab = [[UITabBarItem alloc]initWithTitle:@"Home" image:[UIImage imageNamed:@"HomeTab.png"] tag:0];
UITabBarItem * helpTab = [[UITabBarItem alloc]initWithTitle:@"Help" image:[UIImage imageNamed:@"InfoDarkTab.png"] tag:1];

UIStoryboard * phone = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
StartListTVC *startVC = [phone instantiateViewControllerWithIdentifier:@"StartList"];
HelpWebVC * helpVC = [phone instantiateViewControllerWithIdentifier:@"HelpWeb"];

startVC.tabBarItem = startTab;
helpVC.tabBarItem = helpTab;

NSArray *myViewControllers = [[NSArray alloc] initWithObjects:
startVC,
helpVC, nil];

[self setViewControllers:myViewControllers];

[self.navigationController setNavigationBarHidden:NO animated:NO];

}

最佳答案

您应该将 View Controller 嵌入到 UINavigationController 中,而不是 UITabBarController。

- (void)viewDidLoad {
[super viewDidLoad];

UITabBarItem * startTab = [[UITabBarItem alloc]initWithTitle:@"Home" image:[UIImage imageNamed:@"HomeTab.png"] tag:0];
UITabBarItem * helpTab = [[UITabBarItem alloc]initWithTitle:@"Help" image:[UIImage imageNamed:@"InfoDarkTab.png"] tag:1];

UIStoryboard * phone = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];
StartListTVC *startVC = [phone instantiateViewControllerWithIdentifier:@"StartList"];
HelpWebVC * helpVC = [phone instantiateViewControllerWithIdentifier:@"HelpWeb"];


UINavigationController *startNavVC = [[UINavigationController alloc] initWithRootViewController: startVC];
UINavigationController *helpNavVC = [[UINavigationController alloc] initWithRootViewController: helpVC];
startNavVC.tabBarItem = startTab;
helpNavVC.tabBarItem = helpTab;
NSArray *myViewControllers = [[NSArray alloc] initWithObjects:
startNavVC,
helpNavVC];

[self setViewControllers:myViewControllers];
}

关于ios - 代码中的 UITabBarController 不显示导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58259947/

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