2012-04-30 67 views
0

使用Xcode 4.2,我的應用程序在iOS 5.0模擬器中運行。它運行在iOS 4.2.1的3G iPhone上。它在而不是上運行的iOS 3.1.3的iPod上。如何在iOS 3.1中實例化我的ViewController? (它已經在iOS 4.2.1中運行)

這是樣板代碼,我從任意數量的教程了,但iOS的3.1.3設備上,顯示的是我爲Default.png後,此行失敗:

self.window.rootViewController = self.viewController; 

與「無法識別的選擇發送到實例「我在這裏ykAppDelegate.m

#import "ykAppDelegate.h" 
#import "ykViewController.h" 

@implementation ykAppDelegate 

@synthesize window; 
@synthesize viewController; 

#pragma mark - 
#pragma mark Application lifecycle 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    // Override point for customization after application launch. 

    // Set the view controller as the window's root view controller and display. 
    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; 

    return YES; 
} 

有了比代碼粗略地看一眼更多,我注意到的viewController顯然不是實例化(除了@synthesize);它只是在宣佈我ykAppDelegate.h

#import <UIKit/UIKit.h> 

@class ykViewController; 

@interface ykAppDelegate : NSObject <UIApplicationDelegate> { 
    UIWindow *window; 
    ykViewController *viewController; 
} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet ykViewController *viewController; 

@end 

是否有一個小的調整,我可以因此這將在IOS 3.1的工作?

回答

1

在iOS5之前的操作系統中,UIWindow沒有名爲'rootViewController'的屬性。一個慣用的解決方案是簡單地添加視圖控制器的視圖作爲一個子視圖到應用程序的主要窗口:

[window addSubview:self.myViewController.view]; 
0

這爲我工作

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

    // Override point for customization after application launch. 

    // Set the view controller as the window's root view controller and display. 
    [window addSubview:self.viewController.view]; 
    [self.window makeKeyAndVisible]; 

    return YES; 
} 
相關問題