如何使用 tabbarcontroller 在应用程序加载时分隔视图控制器

发布于 2024-12-14 04:54:04 字数 482 浏览 3 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

云雾 2024-12-21 04:54:04

今天遇到了同样的问题。我必须

[self.window makeKeyAndVisible];

[self.window.rootViewController performSegueWithIdentifier:@"LoginView" sender:self];

调用:所以我假设使用故事板时 makeKeyAndVisible 发生在 didFinishLaunchinWithOptions: 返回之后。因此,当我们调用 Segue 时,它​​发生在屏幕上以外的视图上。

Ran into this same issue today. I had to call:

[self.window makeKeyAndVisible];

before

[self.window.rootViewController performSegueWithIdentifier:@"LoginView" sender:self];

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.

山田美奈子 2024-12-21 04:54:04

我最近遇到了同样的问题。但是,提供的解决方案对我来说并不奏效。

原因是我使用“推”segue 来显示我的登录视图控制器(嵌入在导航控制器中)。将 Segue 的风格从“push”更改为“modal”对我来说很有效。显然,不可能从选项卡栏控制器内启动“推送”segue,而只能从导航控制器内启动。

此外,我没有将该行

[self performSegueWithIdentifier:@"LoginSegue sender:self];

放在应用程序委托的方法 didFinishLaunchingWithOptions:didFinishLaunchingWithOptions: 中,而是放在方法 viewDidAppear: 中。这样做,我不需要以下代码行:

[self.window makeKeyAndVisible];

希望这对其他人有用。

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

[self performSegueWithIdentifier:@"LoginSegue sender:self];

in the method didFinishLaunchingWithOptions:didFinishLaunchingWithOptions: of the app's delegate, but rather in the method viewDidAppear:. Doing so, I did not need the following line of code:

[self.window makeKeyAndVisible];

Hope this is useful to others.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文