简体   繁体   中英

The 'rootViewController' outlet of UIWindow is not available on releases prior to iOS 4.0

I am getting the following error on pre-iOS 4.0 builds:

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.

How and where do I do this programmatically?

Let's pretend you have a CoolViewController class.

Inside your CoolAppDelegate.h you need to have something like this:

@class CoolViewController;

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

Then your CoolAppDelegate.m would need the

application:applicationdidFinishLaunchingWithOptions:

method with some code like this:

- (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;
}

To avoid the error you'll probably need also to remove the reference to the IBOutlet that points to the rootViewController in your .xib file via Interface Builder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM