4

我在 iOS 4.0 之前的版本中收到以下错误:

The 'rootViewController' outlet of UIWindow is not available on releases prior to iOS 4.0. Remove the connection and instead programmatically add the view controller's view to the window after the application finishes launching.

我如何以及在哪里以编程方式执行此操作?

4

1 回答 1

4

假设您有一个 CoolViewController 类。

在你的 CoolAppDelegate.h 中,你需要有这样的东西:

@class CoolViewController;

@interface CoolAppDelegate.h : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    CoolViewController *viewController;
}

那么你的 CoolAppDelegate.m 将需要

application:applicationdidFinishLaunchingWithOptions:

方法与一些像这样的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after app launch.

    // Add your cool controller's view to the window.
    [window addSubview:viewController.view];
    [window makeKeyAndVisible];

    return YES;
}

为避免该错误,您可能还需要通过 Interface Builder 删除对 .xib 文件中指向 rootViewController 的 IBOutlet 的引用。

于 2010-11-09T11:19:09.880 回答