Iphone ';rootViewController';iOS 4.0之前的版本不提供UIWindow的出口

Iphone ';rootViewController';iOS 4.0之前的版本不提供UIWindow的出口,iphone,objective-c,cocoa-touch,xcode,uiwindow,Iphone,Objective C,Cocoa Touch,Xcode,Uiwindow,我在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

我在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.

如何以及在何处以编程方式执行此操作?

让我们假设您有一个CoolViewController类

在CoolAppDelegate.h中,您需要具有以下内容:

@class CoolViewController;

@interface CoolAppDelegate.h : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    CoolViewController *viewController;
}
- (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;
}
方法,具有类似于以下代码:

@class CoolViewController;

@interface CoolAppDelegate.h : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    CoolViewController *viewController;
}
- (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的引用