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

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

问题描述

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

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?

非常感谢

Tom

推荐答案

我试图将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天全站免登陆