gpt4 book ai didi

ios - 在 Storyboard 应用程序上,如何在应用程序期间从 AppDelegate 呈现 View Controller :didFinishLaunchingWithOptions:?

转载 作者:行者123 更新时间:2023-11-28 20:25:44 25 4
gpt4 key购买 nike

我有一个 Storyboard 应用程序, Root View Controller 是 UITableViewController

有时,当我启动应用程序时,我需要呈现一个 View Controller (不需要 Nib 或任何东西)。这就是我尝试这样做的方式:

在我的 UIApplicationDelegate application:application didFinishLaunchingWithOptions::

SplashViewController * splashViewController = [[SplashViewController alloc] init];
splashViewController.semaphore = semaphore;
[self.window.rootViewController presentViewController:splashViewController animated:NO completion:nil];

问题是,此时 UITabBarController 还不在 View 层次结构中,所以我收到此警告:

Warning: Attempt to present <SplashViewController: 0xa786a10> on <UITabBarController: 0xb35d830> whose view is not in the window hierarchy!

将此代码从 AppDelegate 移动到 UITableViewController 的第一个 View Controller 的 viewDidLoad 看起来不对,因为我需要创建一些属性在我的 AppDelegate 中只是为了让我的第一个 View Controller 构建该 View 。这种逻辑不适合那里。

呈现此 View Controller 的正确方法是什么?

最佳答案

在您可以在这里显示 View Controller 之前,窗口必须是关键的并且是可见的。您可以通过执行以下操作来完成此操作:

[self.window makeKeyAndVisible];

所以你的完整代码应该是这样的:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self.window makeKeyAndVisible];

SplashViewController * splashViewController = [[SplashViewController alloc] init];
splashViewController.semaphore = semaphore;
[self.window.rootViewController presentViewController:viewController animated:NO completion:nil];

return YES;
}

关于ios - 在 Storyboard 应用程序上,如何在应用程序期间从 AppDelegate 呈现 View Controller :didFinishLaunchingWithOptions:?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14074062/

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