我是 iOS/Objective-C 的新手,我正在努力学习。我正在阅读 Sam 的《自学 iOS》。我正在做一个名为 Hello Noun 的项目,它不显示 Hello World,而是接受输入并显示“Hello Input”。
在项目中,一切都很好,没有错误。但是当我去构建然后运行应用程序时,它崩溃了:
'NSUnknownKeyException', reason: '[<ViewController 0xa064620> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key setOutput.'
并指向 main.m 文件突出显示这些行;
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
使用的其余代码如下;
视图控制器.m
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *userOutput;
@property (weak, nonatomic) IBOutlet UITextField *userInput;
- (IBAction)setOutput:(id)sender;
@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)setOutput:(id)sender {
self.userOutput.text=self.userInput.text;
}
@end
我对此很陌生,我刚刚了解方向,所以我不太确定发生了什么。任何帮助将不胜感激。