我对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