中聲明當我嘗試編譯這個時,我得到這個錯誤。我需要爲界面中的屬性聲明添加什麼?如果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 2012-02-16 21:52:41