ios - 如何在所有 View 中显示标签栏
<p><p>以下是我的代码,它仅在给定的 2 个标签栏项目上显示标签栏,但在其他 View 中未显示标签栏。</p>
<pre><code> self.window = [ initWithFrame:[ bounds]];
self.startQuizViewController = [ initWithNibName:nil bundle:nil];
self.scoreViewController = [ initWithNibName:nil bundle:nil];
self.startQuizViewController.title = @"QUIZ";
self.scoreViewController.title = @"SCORES";
self.tabBarController = [ init];
self.tabBarController.viewControllers = ;
_navigationController=[initWithRootViewController:self.tabBarController];
;
self.window.rootViewController = self.navigationController;
;
return YES;
</code></pre>
<p>用 <code>didFinishLaunchingWithOptions</code> 编写的代码在 <code>AppDelegate.m.</code></p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>改变这部分:</p>
<pre><code>_navigationController=[initWithRootViewController:self.tabBarController];
;
self.window.rootViewController = self.navigationController;
</code></pre>
<p>到这里:</p>
<pre><code>self.window.rootViewController = self.tabBarController;
</code></pre>
<p>您不能在导航 Controller 中使用 tabbarcontroller。所以只需删除导航 Controller 并将标签栏 Controller 设置为 Root ViewController </p>
<p>编辑:</p>
<pre><code>self.startQuizViewController = [ initWithNibName:nil bundle:nil];
self.scoreViewController = [ initWithNibName:nil bundle:nil];
self.startQuizViewController.title = @"QUIZ";
self.scoreViewController.title = @"SCORES";
self.tabBarController = [ init];
UINavigationController * nav1 = [ initWithRootViewController:self.startQuizViewController];
UINavigationController * nav2 = [ initWithRootViewController:self.scoreViewController];
self.tabBarController.viewControllers = ;
self.window.rootViewController = self.tabBarController;
;
</code></pre>
<p>就是这样。您现在可以将 ViewController 推送到这些 Controller 中,并且可以让标签栏始终存在。</p></p>
<p style="font-size: 20px;">关于ios - 如何在所有 View 中显示标签栏,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/25073947/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/25073947/
</a>
</p>
页:
[1]