0

I am really new to iOS programming. I am just trying to make a button click event and when I run simulator an exception comes up

2014-10-27 12:00:00.859 practiceapp[682:28288] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x7f95fb721120> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key button1.'

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UITextField *textfield;
@property (weak, nonatomic) IBOutlet UIButton *button;

@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)changebuttonaction:(id)sender {

    NSString *st = self.textfield.text;
    self.label.text=st;
    [self.textfield resignFirstResponder];
}



@end

You can find the source here: https://github.com/liaoxsong/practiceapp

rmaddy
  • 314,917
  • 42
  • 532
  • 579
miracle-doh
  • 596
  • 1
  • 4
  • 19
  • Please [do a search on the error](http://stackoverflow.com/search?q=NSUnknownKeyException+this+class+is+not+key+value+coding-compliant+for+the+key) before posting. This is probably one the top 3 most commonly posted questions. – rmaddy Oct 27 '14 at 17:15

2 Answers2

3

The exception message tells all. Your Storyboard/IB connection is set to an outlet named button1 which does not exist. Your property is named button.

To correct this, you will need to remove the broken link in your storyboard or xib file and reconnect your UIButton's referencing outlet to button

Keller
  • 17,051
  • 8
  • 55
  • 72
2

You have three different views which has invalid connection. If you go and look at the connection inspector for your viewcontrollers, you will see that button1, label1 and textField1 are invalid. Those are listed as !.

See the firgure closely here. enter image description here

If you remove button1, label1 and textField1 connection from connection inspector by clicking X button, you should be good to go.

Sandeep
  • 20,908
  • 7
  • 66
  • 106