I had a class category that adds some methods to UIViewController
. I needed to add some instance variables to the category, so I turned it into a custom UIViewController
subclass, and added the instance variables. I then turned the UIViewController
I was displaying into an instance of the new subclass.
Now I'm having trouble loading the new UIViewController
when the application loads. I load the view controller from a nib in my 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;
}
After doing so, an exception is thrown when I call makeKeyAndVisible
on my application's window:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[<ATFIPresentationViewController 0x6c497d0> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key basicPicker.'
Where basicPicker is an IBOutlet
to a UITextField
. This is happening for every IBOutlet
I've defined in my viewController. Why would making my viewController a subclass of my subclass of UIViewController
, prevent anything loading from my nib? The "Files Owner" in the nib is ViewController, not ATFIPresentationViewController
.
EDIT: Well, I got tired of trying to get this to work the "proper" and less typing heavy way. I got it to work by turning the extension into an NSObject, and pass the UIViewController to it. I posted what I was using this for on gitHub if anyone wants to take a look.