我在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.
我如何以编程方式执行此操作?
答案 0 :(得分: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引用。