我只是想知道如何在iOS上創建應用程序。iOS - XCode 4.3'變量'需要一種方法?
我發現這一點:在入門
蘋果的小教程。
你看,在結束之後的整個教程後,我試圖編譯我的項目,當項目即將出現該錯誤消息出現了:
2012-09-03 10:05:46.201 HelloWorld[29361:f803] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<HelloWorldViewController 0x6837c10> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label.'
*** First throw call stack:
(0x13c7022 0x1558cd6 0x13c6ee1 0x9bf022 0x930f6b 0x930edb 0x94bd50 0x23371a 0x13c8dea 0x13327f1 0x23226e 0xd81fc 0xd8779 0xd899b 0x37401 0x37670 0x37836 0x3e72a 0xf596 0x10274 0x1f183 0x1fc38 0x13634 0x12b1ef5 0x139b195 0x12ffff2 0x12fe8da 0x12fdd84 0x12fdc9b 0xfc65 0x11626 0x1c3d 0x1ba5)
terminate called throwing an exception
我的猜測是,那裏有我做了一個連接錯了,但是什麼?
我甚至複製粘貼最後.m和.h他們給你,但它不會編譯。
屬性 '可變' 需要方法 'setLabel' 被定義 - 使用@synthetize
變量和setLabel改變6倍(不同的警告)。
我在做什麼錯?
-------編輯這是我viewcontroller.h
#import "HelloWorldViewController.h"
@interface HelloWorldViewController()
@property (weak, nonatomic) IBOutlet UITextField *textField;
@property (weak, nonatomic) IBOutlet UILabel
*label;
- (IBAction)changeGreeting:(id)sender;
@end
@implementation HelloWorldViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setTextField:nil];
[self setLabel:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)changeGreeting:(id)sender {
self.userName = self.textField.text;
NSString *nameString = self.userName;
if ([nameString length] == 0) {
nameString = @"World";
}
NSString *greeting = [[NSString alloc] initWithFormat:@"Hello, %@!", nameString];
self.label.text = greeting;
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == self.textField) {
[theTextField resignFirstResponder];
}
return YES;
}
@end
你需要證明你是如何實施或在HelloWorldViewController合成標籤和設置標籤。 – Abizern