にいくつかのメソッドを追加するクラスカテゴリがありましたUIViewController
。カテゴリにインスタンス変数を追加する必要があったので、それをカスタムUIViewController
サブクラスに変換し、インスタンス変数を追加しました。次に、UIViewController
表示していたものを新しいサブクラスのインスタンスに変換しました。
UIViewController
アプリケーションのロード時に新しいものをロードするのに問題があります。私は私のペン先からビューコントローラーをロードしますAppDelegate
:
- (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
その後、アプリケーションのウィンドウを呼び出すと、例外がスローされます。
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
ですUITextField
。これはIBOutlet
、viewControllerで定義したすべての場合に発生します。viewControllerをのサブクラスのサブクラスにUIViewController
すると、ペン先からの読み込みが妨げられるのはなぜですか?ペン先の「ファイル所有者」はViewControllerであり、ではありませんATFIPresentationViewController
。
編集:まあ、私はこれを「適切な」そしてより少ないタイピングの重い方法で動作させることを試みることにうんざりしました。拡張機能をNSObjectに変換し、UIViewControllerを渡すことで機能するようになりました。誰かが見てみたいと思ったら、私はこれを使っていたものをgitHubに投稿しました。