1
我在iOS上跟隨Apple的「Hello」教程,我想知道爲什麼需要聲明「userName」變量(稍後會在代碼中進行訪問)。它不是由合成語句生成的嗎?IOS sythesize - 什麼時候聲明一個內部變量?
@interface HelloWorldViewController : UIViewController {
NSString *userName;
}
- (IBAction)changeGreeting:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UITextField *testField;
@property (nonatomic, copy) NSString *userName;
下面是合成的實現:
@synthesize label=_label;
@synthesize testField=_testField;
@synthesize userName=_userName;
不是 - 它是全新的。它使用XCode 4.2,故事板,拖放代碼生成等。 –
他們可能會重複使用以前教程中的代碼。 – Randall