簡體   English   中英

UIWindow的'rootViewController'出口在iOS 4.0之前的版本中不可用

[英]The 'rootViewController' outlet of UIWindow is not available on releases prior to 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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM