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

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

问题描述

我已经被这个警告困住了好几个小时了。我环顾四周寻找答案,尝试了我找到的所有答案,但找不到解决办法。这是我所拥有的代码的破败,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!

推荐答案

设置窗口的 rootViewController 很奇怪在应用程序:didFinishLaunchingWithOptions:如果您有 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 的实例,连接到文件所有者的委托出口。 xib还包含 UIWindow ,其 rootViewController 插座连接到 UIViewController (或子类,例如 UINavigationController ),它也在xib中。当应用程序委托收到应用程序: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天全站免登陆