我對Objective-C中的屬性的使用感到困惑。如果我創建一個新的IBOutlet
這樣的:Objective-C屬性規則
IBOutlet UISlider *uploadSlider;
,然後定義屬性滑塊,所以我可以用它的getter和setter方法:
@property (nonatomic, strong) IBOutlet UISlider *uploadSlider;
然後@synthesize
它在實現文件,是什麼是實際使用該財產的正確方法?例如,如果我想改變滑塊的軌道像,我叫
[uploadSlider setMaximumTrackImage:[UIImage imageNamed:@"An image"] forState:UIControlStateSelected];
或者:
[self.uploadSlider setMaximumTrackImage:[UIImage imageNamed:@"An image"] forState:UIControlStateSelected];
,我與self
前綴的方法是唯一可用的定義屬性之後,這讓我想到這是正確的選擇。但我不明白爲什麼。我甚至需要屬性來訪問這些方法?另外,如果我使用點語法來獲取或設置與某個對象有關的信息,我是否必須爲該對象定義屬性,即使我沒有直接訪問它的某個實例方法?
可能重複: http://stackoverflow.com/questions/2032826/property-synthesize http://stackoverflow.com/questions/6425588/property-implementation-of-variables-in-objective-c HTTP :http://stackoverflow.com/questions/2032826/property-synthesize http://stackoverflow.com/questions/806379/whats-the-difference-between-property-and-synthesize http://stackoverflow.com/questions/6112283/question-about-synthesize http://stackoverflow.com/questions/1398305/objective-c-property-access – CodaFi 2012-04-27 01:30:06