-1
我是iOS/Objective-C的新品,我正在努力學習。我正在跟隨薩姆教你自己的iOS。我正在做一個名爲Hello Noun的項目,它不是顯示Hello World,而是輸入一個輸入並顯示「Hello Input」。這個類不是密鑰編碼兼容密鑰setOutput
在項目上工作,一切都很好,沒有錯誤。但是當我去建立,然後運行應用程序,它崩潰說:
'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]));
}
}
其餘使用的代碼如下;
ViewController.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
我是新來這一點,我只是讓我的軸承,所以我不太清楚發生了什麼。任何幫助將不勝感激。
在文本框中分配文本而不是標籤 – NullData
http://stackoverflow.com/a/5930648/1835803您是否嘗試過? –