Reputation: 307
I am working a project with multiple UIViewController
s. I just added a new one and when I click the new button, the app crashes with the following error.
2011-10-11 22:51:57.227 BG-Prep[9156:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ResourcesViewController 0x4b28540> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key delegate.'
* Call stack at first throw:
The code is identical (except for the file names) to two other pages that work fine. What is this telling me?
- (IBAction)resourceButtonTapped:(id)sender;
{
NSLog(@"Tapped the resource button");
ResourcesViewController *resourcesViewController = [[[ResourcesViewController alloc]
initWithNibName:@"ResourcesViewController" bundle:[NSBundle mainBundle]] autorelease];
NSLog(@"receiver's type: %@", NSStringFromClass([resourcesViewController class]));
resourcesViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:resourcesViewController animated:YES];
}
If I uncomment the two lines, I get the follow:
2011-10-12 14:38:51.533 BG-Prep[10070:207] Tapped the resource button
2011-10-12 14:38:51.535 BG-Prep[10070:207] receiver's type: ResourcesViewController
The last line [self presentModalViewController:resourcesViewController animated:YES];
is causing the App crash, but why ?
Upvotes: 0
Views: 283
Reputation: 124997
So, the view controller throws an exception when you try to present it modally. That's the first time the controller's view will be accessed, so the controller will load the nib at that point. When that happens, the nib loading mechanism tries to set a value for the key delegate
in the view controller, and you crash because the view controller apparently doesn't have a delegate
property. Perhaps you had one but removed it and forgot to fix up your nib?
Upvotes: 0
Reputation: 2376
Usually this error suggests you didn't set a view outlet in your nib. Go into the user interface nib, right click on "File's owner". Drag the circle to the right of "view" onto the root view of your nib. This will fix you right up usually.
If the file's owner is set properly, then that suggests you have an IBOutlet specified on one of your views that isn't present in your view controller definition. Right click on each of your views (including your root view) and check to make sure there are no yellow triangle warnings next to any of your IBOutlets.
Upvotes: 2