以下是我的代码,它仅在给定的 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;
用 didFinishLaunchingWithOptions
编写的代码在 AppDelegate.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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |