我在 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;
}
为避免该错误,您可能还需要通过 Interface Builder 删除对指向 .xib 文件中的 rootViewController 的 IBOutlet 的引用。
关于iphone - UIWindow 的 'rootViewController' 导出在 iOS 4.0 之前的版本上不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4040610/