我遇到了这个问题,但是我在这个论坛或互联网上找到的所有信息似乎都无法帮助我。
似乎有两个地方可能会出现此错误:
- main.m - 我的函数如下所示:
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
UIApplicationMain
中的最后一个参数返回我的 AppDelegate
类的 NSString
值。因此,这工作正常。
2.AppDelegate.m - 有一种设置 Root View Controller 的“旧”方法,如下所示:
[self.window addSubview:rootViewController];
但是,在我的应用程序中,它已经更新为:
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
因此,目前互联网上的所有信息均无效。有点令人费解的是,我的同事可以让它在他的计算机上完美运行 - 他是向我发送应用程序源代码的人,因此所有设置和代码应该完全相同。
我正在尝试在模拟器中启动它。它是针对 iOS 5 构建的,但我试图在 iOS 6.0 模拟器上运行它。
我有最新的 XCode (4.5.1)。
有什么原因会发生这种情况吗?我该如何纠正它?
非常感谢
汤姆
最佳答案
我在尝试将 UITableView 添加到单 View 应用程序时遇到了完全相同的事情。相反,创建一个默认的 Master-Detail 应用程序项目 (file->new->target->...) 并查看 AppDelegate 的 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;
}
与其直接将 View Controller 设置为窗口的 rootViewController,不如为 initWithRootViewController 创建一个使用 View Controller 初始化的导航 Controller ,然后将该导航 Controller 设置为窗口的 rootViewController。 (请注意,您还必须将导航 Controller 存放在属性中,以免它被破坏)。
关于ios - 应用程序窗口预计在应用程序启动结束时有一个 Root View Controller ——即使所有已知问题都已修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12784411/