1

I have added a UIViewController to my project and it works fine, except when I add the buttons. I am getting an error: * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cancel.'

Here is the code for the header and implementation files. All of this code is auto-generated when I use the Assistant Editor and CTRL drag from each control to the header file.

SignUpViewController.h:

#import <UIKit/UIKit.h>

@interface SignUpViewController : UIViewController {


    IBOutlet UITextField *leader;
    IBOutlet UITextField *emailAddress;
    IBOutlet UITextField *firstName;
    IBOutlet UIScrollView *scrollView;
    IBOutlet UITextField *lastName;
}
- (IBAction)cancel:(id)sender;
- (IBAction)signUp:(id)sender;

@end

SignUpViewController.m

#import "SignUpViewController.h"

@interface SignUpViewController ()

@end

@implementation SignUpViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
   self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
   if (self) {
   }
   return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [scrollView setScrollEnabled:YES];
    [scrollView setContentSize:CGSizeMake(320, 1000)];

}

- (void)viewDidUnload
{
    firstName = nil;
    lastName = nil;
    emailAddress = nil;
    leader = nil;
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}


- (IBAction)cancel:(id)sender {
}

- (IBAction)signUp:(id)sender {
}
@end

I am not sure why the error is occuring. Any ideas?

Piyush Dubey
  • 2,416
  • 1
  • 24
  • 39
rosst400
  • 563
  • 2
  • 7
  • 19
  • This sounds like a problem in Interface Builder. Does the problem occur when you put the buttons on your view, or when you try to attach the `cancel` event to one of them? – Cowirrie Apr 07 '12 at 22:17
  • So just how are you attaching the event? Do you end up with `cancel` mentioned on the `Connections` inspector under `Sent Events`, `Touch Up Inside`? If you had to type the name of your `cancel` event, it was probably in the wrong place. [This video](http://www.youtube.com/watch?v=7eFbbvVaYOU) may help, especially at 2:50. – Cowirrie Apr 07 '12 at 22:43

1 Answers1

3

This error happens when you delete an IBOutlet in you source, but don't unwire it in Interface Builder. Check your XIB file to make sure that no old properties are remaining. Old wired properties will show up with an exclamation point (!) in them.

borrrden
  • 33,256
  • 8
  • 74
  • 109