为什么模态视图控制器没有出现在 applicationDidFinishLaunchingWithOptions 中?

发布于 2025-01-01 16:53:49 字数 826 浏览 0 评论 0原文

每当应用程序运行时,我的应用程序都会呈现一个模式视图控制器(密码输入表单)。我在两个应用程序委托方法中呈现视图控制器:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self.window.rootViewController presentModalViewController:self.passcodeViewController animated:NO];
    //...
    return YES;
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    if (!self.passcodeViewController.view.window) {
        [self.window.rootViewController presentModalViewController:self.passcodeViewController animated:NO];
    }
}

application:didFinishLaunchingWithOptions: 方法中呈现模式视图控制器的调用不呈现视图控制器,而在 applicationDidBecomeActive 中的调用:是的。这是为什么呢?

编辑:根据下面的评论,我想提一下,我正在使用故事板,并且 self.window.rootViewController 确实指向一个对象(基本上,它不是零)

My application presents a modal view controller (a passcode entry form) whenever the application is run. I present the view controller in two application delegate methods:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self.window.rootViewController presentModalViewController:self.passcodeViewController animated:NO];
    //...
    return YES;
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    if (!self.passcodeViewController.view.window) {
        [self.window.rootViewController presentModalViewController:self.passcodeViewController animated:NO];
    }
}

The call to present the modal view controller in the application:didFinishLaunchingWithOptions: method does not present the view controller, where as the call in applicationDidBecomeActive: does. Why is this?

EDIT: I wanted to mention, per the comments below, that I'm using a Storyboard and that self.window.rootViewController does indeed point to an object (basically, it's not nil)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

半寸时光 2025-01-08 16:53:49

来自 UIApplicationDelegate 协议手册参考:

在您的应用程序启动及其主笔尖后调用它
文件已加载。调用此方法时,您的
应用程序处于非活动状态。

From the UIApplicationDelegate Protocol Manual Reference:

It is called after your application has been launched and its main nib
file has been loaded. At the time this method is called, your
application is in the inactive state.

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