应用程序窗口应该在应用程序启动结束时有一个根视图控制器 - 即使所有已知问题都已修复 [英] Application windows are expected to have a root view controller at the end of application launch - even with all known issues fixed

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

问题描述

我有这个问题,但是我在这个论坛或一般互联网上找不到的信息似乎都无法帮助我.

I have this problem, however none of the information I can find on this forum or the internet in general seems to be able to help me.

似乎有两个地方会出现此错误:

There seem to be two places where this error can come about:

  1. main.m - 我的函数如下所示:

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

UIApplicationMain 中的最后一个参数返回我的 AppDelegate 类的 NSString 值.因此,这工作正常.

The last argument in UIApplicationMain returns an NSString value of the class of my AppDelegate. This is therefore working fine.

2.AppDelegate.m - 有一种旧"的方式来设置根视图控制器,如下所示:

2.AppDelegate.m - there is an "older" way of setting the root view controller which is like this:

  [self.window addSubview:rootViewController];

但是,在我的应用中,它已经更新为:

However, in my app it has already been updated to:

self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];

因此,互联网上的当前信息均无效.这有点令人费解,因为我的同事可以让它在他的计算机上完美运行 - 他是向我发送应用程序源代码的人,因此所有设置和代码应该完全相同.

So none of the current information on the internet works. It is slightly more puzzling as my colleague can get it to work on his computer perfectly fine - he was the one that sent me the app source code so all the settings and code should be exactly the same.

我正在尝试在模拟器中启动它.它是针对 iOS 5 构建的,但我正在尝试在 iOS 6.0 模拟器上运行它.

I am trying to launch this in the simulator. It is built against iOS 5, but I'm trying to run it on the iOS 6.0 simulator.

我有最新的 XCode (4.5.1).

I have the latest XCode (4.5.1).

有什么原因会发生这种情况吗?我该如何纠正它?

Is there any reason this would be happening? And how can I rectify it?

非常感谢

汤姆

推荐答案

我在尝试将 UITableView 添加到单视图应用程序时遇到了完全相同的事情.相反,创建一个默认的 Master-Detail Application 项目(file->new->target->...)并查看 AppDelegate 的 didFinishLaunchingWithOptions 实现:

I ran into exactly the same thing trying to add a UITableView to a single-view app. Instead, create a default Master-Detail Application project (file->new->target->...) and see the AppDelegate's implementation of didFinishLaunchingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

MDMasterViewController *masterViewController = [[MDMasterViewController alloc] initWithNibName:@"MDMasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}

与其直接将视图控制器设置为窗口的 rootViewController,不如为 initWithRootViewController 创建一个使用视图控制器初始化的导航控制器,然后将该导航控制器设置为窗口的 rootViewController.(请注意,您还必须将导航控制器隐藏在属性中,以免被破坏).

Rather than directly setting your view controller as the window's rootViewController, you need to create a navigation controller init'ed with your view controller for initWithRootViewController, then set that nav controller as the window's rootViewController. (Notice you also have to squirrel away that nav controller in a property so it doesn't get destructed).

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

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