gpt4 book ai didi

ios - 在不使用 RootViewController 的情况下显示 UITabBar

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

我有一个 LoginViewController,它是 RootViewController。此 ViewController 不应包含 TabBar。 ViewController 的其余部分应该包含 UITabBar,但它没有显示。如果我将 tabBar 设为 rootController,它将在 viewcontrollers 中显示 tabBar。这也会使 firsttab 成为它不应该的 rootviewcontroller。

我的问题是,我怎样才能使登录 View 成为没有 tabBar 的 rootViewController,并且仍然在其他 View Controller 中显示 tabBar?

我的代码:

tabBarController = [[UITabBarController alloc] init];

MenuViewController *firstTab = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstTab];


FixtureViewController *secondTab = [[FixtureViewController alloc] initWithNibName:@"FixtureViewController" bundle:nil];
UINavigationController *navController2 = [[UINavigationController alloc] initWithRootViewController:secondTab];

WorldCupViewController *thirdTab = [[WorldCupViewController alloc] initWithNibName:@"WorldCupViewController" bundle:nil];
UINavigationController *navController3 = [[UINavigationController alloc] initWithRootViewController:thirdTab];

LoginViewController *loginView = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:loginView];



self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[navController, navController2, navController3];

navController.tabBarItem.image = [UIImage imageNamed:@"message-7"];
navController2.tabBarItem.image = [UIImage imageNamed:@"football-32"];
navController3.tabBarItem.image = [UIImage imageNamed:@"trophy-32"];
[[UITabBar appearance] setTintColor:[UIColor colorWithRed:110/255.0f green:89/255.0f blue:196/255.0f alpha:1.0f]];

[self.window setRootViewController:navController4];
[self.window makeKeyAndVisible];

最佳答案

您需要做的是将应用程序从 LoginViewController 转换到 Tabbar。我建议做的是用 TabBar 替换 LoginViewController 作为 rootViewController。

这是一些示例代码,在您的 AppDelegate 中执行此操作

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

LoginViewController *loginView = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
UINavigationController *navController4 = [[UINavigationController alloc] initWithRootViewController:loginView];

[self.window setRootViewController:navController4];
[self.window makeKeyAndVisible];

return YES;
}

-(void)transitionToTabBar
{

// Set the TabBar how you are in your sample code, this is just an example.
[self.window setRootViewController:[[UITabBarController alloc] initWithNibName:@"SomeNib" bundle:Nil]];

[UIView transitionWithView:self.window duration:0.5f options:UIViewAnimationOptionTransitionCurlDown animations:^{
[self.window makeKeyAndVisible];
} completion:nil];
}

关于ios - 在不使用 RootViewController 的情况下显示 UITabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22167245/

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