我對iOS編程真的很陌生。我只是試圖讓一個按鈕單擊事件,當我運行模擬器異常出現按鈕點擊事件的NSUnknownKeyException
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
您可以找到來源:https://github.com/liaoxsong/practiceapp
請[在錯誤上搜索](http://stackoverflow.com/search?q=NSUnknownKeyException+this+class+is+not+key+value+coding-compliant+for+the+key)張貼。這可能是最常發佈的前3個問題之一。 – rmaddy 2014-10-27 17:15:20