如何使用 tabbarcontroller 在应用程序加载时分隔视图控制器
我使用 tabbarcontroller 作为根视图控制器。不幸的是,使用新的故事板功能,事实证明很难在应用程序负载上连接视图控制器 - 登录页面。
我正在使用下面的代码:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
[tabBarController performSegueWithIdentifier:@"loginPage" sender:self];
Segue 设置正确。我进入其中一个选项卡视图控制器并创建了一个 IBAction,它成功地进行了连接。 提前致谢。
I am using a tabbarcontroller as the root view controller. Unfortunately, using the new storyboard functionality, it is proving difficult to segue a view controller - Login Page - on the app load.
I am using the below code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
[tabBarController performSegueWithIdentifier:@"loginPage" sender:self];
The segue is set up properly. I went into one of the tabs view controllers and made an IBAction and it successfully segued.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
今天遇到了同样的问题。我必须
先
调用:所以我假设使用故事板时 makeKeyAndVisible 发生在 didFinishLaunchinWithOptions: 返回之后。因此,当我们调用 Segue 时,它发生在屏幕上以外的视图上。
Ran into this same issue today. I had to call:
before
So I'm assuming that when using storyboards the makeKeyAndVisible happens after didFinishLaunchinWithOptions: returns. So when were calling the segue its happening on a view thats not onscreen.
我最近遇到了同样的问题。但是,提供的解决方案对我来说并不奏效。
原因是我使用“推”segue 来显示我的登录视图控制器(嵌入在导航控制器中)。将 Segue 的风格从“push”更改为“modal”对我来说很有效。显然,不可能从选项卡栏控制器内启动“推送”segue,而只能从导航控制器内启动。
此外,我没有将该行
放在应用程序委托的方法
didFinishLaunchingWithOptions:didFinishLaunchingWithOptions:
中,而是放在方法viewDidAppear:
中。这样做,我不需要以下代码行:希望这对其他人有用。
I ran recently into the same issue. However, the solution provided did not work out for me.
The reason was that I used a "push" segue to display my login view controller (which was embedded inside a navigation controller). Changing the style of the segue from "push" to "modal" did the trick for me. Apparently, it is not possible to initiate a "push" segue from within a tab bar controller but only from within a navigation controller.
Furthermore, I did not put the line
in the method
didFinishLaunchingWithOptions:didFinishLaunchingWithOptions:
of the app's delegate, but rather in the methodviewDidAppear:
. Doing so, I did not need the following line of code:Hope this is useful to others.