ios - 应用程序窗口预计在应用程序启动结束时有一个 Root View Controller ——即使所有已知问题都已修复

标签 ios ios5 ios-simulator ios6

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

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

  1. 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/

相关文章:

ios - 在 map 上标记位置的更好方法

ios - 上传成功后无法在 iTunes 连接中看到我的新版本

ios - 在 SwiftUI 中检测 DragGesture 取消

ios - iOS 6.1 中的闪烁屏幕问题

model-view-controller - 在主/详细信息应用程序的主视图 Controller 中动态提供 uitableview 的问题

iphone - XCode 4.5 iOS 6.0 模拟器和旋转问题

ios - iOS模拟器仅占据窗口的一部分

iphone - 使用 addTarget 将 UIView 中的 UIButton 定位为目标

iphone - UIFont 类别的单元测试用例编写问题

ios - 文本字段边框不仅仅出现在 iPad2 中,在 iPad Air 或可调整大小的 iPad 中也出现了