应用程序窗口应该在应用程序启动警告结束时有一个根视图控制器 [英] Application windows are expected to have a root view controller at the end of application launch warning

查看:21
本文介绍了应用程序窗口应该在应用程序启动警告结束时有一个根视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经被这个警告困扰了几个小时了.我环顾四周寻找答案,尝试了我找到的所有答案,但找不到解决方案.这是我拥有的代码的概要,默认情况下由 Xcode 生成.

I have been stuck with this warning for several hours now. I've looked around SO for answers, attempted all the ones I found and couldn't find the solution. Here's the run-down of the code I have, which Xcode generated by default.

这是在我的 AppDelegate 中

This is in my AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

我在 main.m 上有这个(根据 这个答案)

I have this on main.m (according to this answer)

int main(int argc, char *argv[])
{
    @autoreleasepool {
        int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        return retVal;
    }
}

我的 MainWindow.xib 中的所有连接也正确连接.所以我现在很茫然.有什么我可能会遗漏的吗?提前致谢!

I also have all the connections in my MainWindow.xib connected correctly. So I'm at a loss right now. Anything that I could be missing? Thanks in advance!

推荐答案

application:didFinishLaunchingWithOptions: 中设置窗口的 rootViewController 很奇怪,如果你有一个 MainWindow.xib.通常一个项目遵循以下三个模板之一:

It's odd to be setting your window's rootViewController in application:didFinishLaunchingWithOptions: if you have a MainWindow.xib. Usually a project follows one of three templates:

  • 有些项目有一个MainWindow.xib.目标的主界面"在目标的摘要"选项卡(或其 Info.plist)中设置为MainWindow".这个xib 的文件所有者是UIApplication.xib 包含一个 AppDelegate 实例,连接到文件所有者的 delegate 出口.xib 还包含一个 UIWindow,其 rootViewController 插座连接到一个 UIViewController(或子类,例如 UINavigationController),这也在 xib 中.当应用程序委托收到 application:didFinishLaunchingWithOptions: 消息时,xib 已完全加载,因此窗口及其根视图控制器已经设置.

  • Some projects have a MainWindow.xib. The target's "Main Interface" is set to "MainWindow" in the target's Summary tab (or in its Info.plist). This xib's File's Owner is UIApplication. The xib contains an instance of AppDelegate, connected to the File's Owner's delegate outlet. The xib also contains a UIWindow, whose rootViewController outlet is connected to a UIViewController (or subclass, such as UINavigationController), which is also in the xib. By the time the application delegate receives the application:didFinishLaunchingWithOptions: message, the xib is entirely loaded, so the window and its root view controller are already set up.

其他项目没有 MainWindow.xib.目标的主界面"是空的.相反,UIApplicationMain 函数创建了一个 AppDelegate 的实例,将其设置为 UIApplication 的委托,并将其发送给 应用程序:didFinishLaunchingWithOptions: 消息.应用程序委托通过创建一个 UIWindow、创建一个(或多个)视图控制器并设置窗口的 rootViewController 属性来处理该消息.默认版本如下所示:

Other projects don't have a MainWindow.xib. The target's "Main Interface" is empty. Instead, the UIApplicationMain function creates an instance of AppDelegate, sets it as the UIApplication's delegate, and sends it the application:didFinishLaunchingWithOptions: message. The app delegate handles that message by creating a UIWindow, creating a view controller (or several), and setting the window's rootViewController property. The default version looks like this:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

  • 有些项目有一个 MainStoryboard.storyboard.我不打算详细描述这一点,因为它似乎与您的问题无关.

  • Some projects have a MainStoryboard.storyboard. I'm not going to describe this in detail because it doesn't seem relevant to your problem.

    您描述的问题听起来像是您使用了第一个模板的一半和第二个模板的一半.那行不通.您需要决定采用哪种方法,然后全力以赴.

    The problem you're describing makes it sound like you're using half of the first template, and half of the second template. That won't work. You need to decide which approach you're taking, and go all-in.

    这篇关于应用程序窗口应该在应用程序启动警告结束时有一个根视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆