2012-08-12 99 views
0

我有一個類別類別,它向UIViewController添加了一些方法。我需要在類別中添加一些實例變量,所以我將它變成了一個自定義的UIViewController子類,並添加了實例變量。然後我把UIViewController變成了一個新的子類的實例。將UIViewController上的類別轉換爲自定義子類

現在,我在加載應用程序時加載新的UIViewController時遇到問題。我加載從筆尖視圖控制器在我AppDelegate

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: 
'[<ATFIPresentationViewController 0x6c497d0> setValue:forUndefinedKey:]: 
this class is not key value coding-compliant for the key basicPicker.' 

凡basicPicker是IBOutlet到:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     self.viewController = [[ATFIPresentationViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil]; 
    } else { 
     self.viewController = [[ATFIPresentationViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil]; 
    } 
    self.window.rootViewController = self.viewController; 
    [self.window makeKeyAndVisible]; //Crashes Here 
    return YES; 
} 

這樣做之後,一個例外是當我打電話makeKeyAndVisible我的應用程序的窗口中拋出UITextField。這發生在我在viewController中定義的每個IBOutlet。爲什麼會讓我的viewController成爲我的子類UIViewController的一個子類,防止從我的筆尖加載任何東西?筆尖中的「文件所有者」是ViewController,而不是ATFIPresentationViewController

編輯:好吧,我厭倦了試圖讓這工作的「適當」,少打字沉重的方式。我通過將擴展轉換爲NSObject來實現它,並將UIViewController傳遞給它。如果有人想看,我發佈了我在gitHub上使用的這個。

+0

您是否擁有ivars或物業網點? – Farcaller 2012-08-12 16:35:04

+0

我已經嘗試了兩種方法,並且它們產生相同的錯誤。 – 2012-08-12 16:57:05

+0

這個問題可能的重複:http://stackoverflow.com/questions/3088059/this-class-is-not-key-value-coding-compliant-for-the-key – jonkroll 2012-08-12 17:37:01

回答

0

發生此錯誤是因爲您的筆尖試圖將某個值設置爲名稱爲basicPicker的屬性沒有屬性的實例。這表明您正在將消息發送給錯誤類型的對象。

您需要在您的nib文件中將您的File's Owner的類設置爲您創建的新UIViewController子類,而不僅僅是默認的UIViewController。在您的筆尖中選擇File's Owner,您可以在右側面板的「實用程序」第三個選項卡中更改該選項卡,名稱爲Xcode中的Identity Inspector,位於頂部。

相關問題