我有一個類別類別,它向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上使用的這個。
您是否擁有ivars或物業網點? – Farcaller 2012-08-12 16:35:04
我已經嘗試了兩種方法,並且它們產生相同的錯誤。 – 2012-08-12 16:57:05
這個問題可能的重複:http://stackoverflow.com/questions/3088059/this-class-is-not-key-value-coding-compliant-for-the-key – jonkroll 2012-08-12 17:37:01