이 코드를 컴파일하려고하면이 오류가 발생합니다. 인터페이스의 속성 선언에 무엇을 추가해야합니까? textBox가 인스턴스 변수 인 경우 속성으로 선언해야하는 이유는 무엇입니까?속성 구현시 인터페이스에 선언이 있어야합니다.
ViewController.h
#import <UIKit/UIKit.h>
@interface TNRViewController : UIViewController {
IBOutlet UITextField *textBox;
IBOutlet UILabel *label;
}
- (IBAction)button:(id)sender;
@end
ViewController.m
#import "TNRViewController.h"
@implementation TNRViewController
@synthesize textBox;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)dealloc {
[textBox release];
[label release];
[super dealloc];
}
- (IBAction)button:(id)sender {
NSString *Name = textBox.text;
NSString *Output = Nil;
Output = [[NSString alloc] initWithFormat:@"%@ says: Hello World!", Name];
label.text = Output;
[Output release];
}
- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
[textBox resignFirstResponder];
return YES;
}
@end
감사를 텍스트 필드에 액세스합니다. @synthesize 행을 제거한 후에 작동합니다. – pdenlinger