iphone – UIWindow的’rootViewController’出口在iOS 4.0之前的版本上不可用

前端之家收集整理的这篇文章主要介绍了iphone – UIWindow的’rootViewController’出口在iOS 4.0之前的版本上不可用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在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;
}

然后你的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;
}

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

猜你在找的Xcode相关文章