gpt4 book ai didi

ios - 如何在所有 View 中显示标签栏

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:21:51 25 4
gpt4 key购买 nike

以下是我的代码,它仅在给定的 2 个选项卡栏项目上显示选项卡栏,但在其他 View 中不显示选项卡栏。

 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

self.startQuizViewController = [[StartQuizViewController alloc] initWithNibName:nil bundle:nil];
self.scoreViewController = [[ScoreViewController alloc] initWithNibName:nil bundle:nil];

self.startQuizViewController.title = @"QUIZ";
self.scoreViewController.title = @"SCORES";

self.tabBarController = [[UITabBarController alloc] init];

self.tabBarController.viewControllers = [NSArray arrayWithObjects:self.startQuizViewController,self.scoreViewController,nil];

_navigationController=[[UINavigationController alloc]initWithRootViewController:self.tabBarController];

[self.window addSubview:self.navigationController.view];
self.window.rootViewController = self.navigationController;

[self.window makeKeyAndVisible];
return YES;

代码写在 didFinishLaunchingWithOptionsAppDelegate.m.

最佳答案

改变这部分:

_navigationController=[[UINavigationController alloc]initWithRootViewController:self.tabBarController];

[self.window addSubview:self.navigationController.view];
self.window.rootViewController = self.navigationController;

为此:

self.window.rootViewController = self.tabBarController;

您不能在导航 Controller 中使用 tabbarcontroller。所以只需删除导航 Controller 并将标签栏 Controller 设置为 Root View Controller

编辑:

self.startQuizViewController = [[StartQuizViewController alloc] initWithNibName:nil bundle:nil];
self.scoreViewController = [[ScoreViewController alloc] initWithNibName:nil bundle:nil];

self.startQuizViewController.title = @"QUIZ";
self.scoreViewController.title = @"SCORES";

self.tabBarController = [[UITabBarController alloc] init];

UINavigationController * nav1 = [[UINavigationController alloc] initWithRootViewController:self.startQuizViewController];

UINavigationController * nav2 = [[UINavigationController alloc] initWithRootViewController:self.scoreViewController];


self.tabBarController.viewControllers = [NSArray arrayWithObjects:nav1, nav2, nil];


self.window.rootViewController = self.tabBarController;

[self.window makeKeyAndVisible];

就是这样。您现在可以将 View Controller 推送到这些 Controller 中,并且标签栏始终在那里。

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

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