gpt4 book ai didi

ios - ios7中如何显示所有tabBar标题

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

基本上我无法在运行我的应用程序时显示所有 tabBar 项目,只显示第一个 View Controller :

enter image description here

我实际上必须单击一个选项卡才能显示其项目:

enter image description here

这是我在 Appdelegate.m 中的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Initialize window
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

// Set background colors for both NavBar and TabBar
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.157 green:0.718 blue:0.553 alpha:1]];
[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:0.141 green:0.216 blue:0.263 alpha:1]];

// Initialize your five tab controllers. with each tab has its own navigation controller
HomePageView *homePageView = [[HomePageView alloc]init];
UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:homePageView];

ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];

FeedViewController *feedViewController=[[FeedViewController alloc]init];
UINavigationController *nav3 = [[UINavigationController alloc]initWithRootViewController:feedViewController];

ListeningSessionViewController *listeningSessionViewController= [[ListeningSessionViewController alloc]init];
UINavigationController *nav4 = [[UINavigationController alloc]initWithRootViewController:listeningSessionViewController];

RecievedViewController *recievedViewController =[[RecievedViewController alloc]init];
UINavigationController *nav5 = [[UINavigationController alloc]initWithRootViewController:recievedViewController];

// initialize tabbarcontroller,set your viewcontrollers and change its color.
self.tabC = [[UITabBarController alloc]init];
NSArray* controllers = [NSArray arrayWithObjects: nav1,nav2,nav3,nav4,nav5, nil];
[self.tabC setViewControllers: controllers animated:NO];
[_window addSubview:self.tabC.view];

// Show window
[self.window makeKeyAndVisible];


return YES;
}

最佳答案

我猜您是在 Controller 的 viewDidLoad 或 viewDidAppear 方法中设置标题。这是行不通的,因为虽然所有 Controller 都在应用程序委托(delegate)中实例化,但只有索引为 0 的 Controller 加载了 View ,因此不会为其他 Controller 运行 viewDidLoad。相反,您应该在应用程序委托(delegate)中的导航 Controller 上设置标题,

ProfileViewController *profileViewController=[[ProfileViewController alloc]init];
UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:profileViewController];
nav2.tabBarItem.title = @"Profile";

关于ios - ios7中如何显示所有tabBar标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24216546/

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