Tag: setter

重写setter方法,并获得“xxx隐藏实例variables的本地声明”

我有一个整型variables,例如timeSignature,在.h文件中声明它,并合成了一对setter / getter方法: 在.h: @interface Metronome : NSObject { int timeSignature; } @property (nonatomic) int timeSignature; 在.m中: @synthesize timeSignature; 我希望覆盖setter方法:当用户为它设置一个新的值时,它会做一些其他的事情,以及更改为新的值: – (void) setTimeSignature:(int)timeSignature { self.timeSignature = timeSignature; //hides instance variable warning at this line [self doesSomethingElse]; } inheritance人的问题,本地variables和实例variables具有相同的名称。 我怎样才能避免这一点?

为什么UILabel没有初始化?

代码来自Stanford CS193p。 我添加了一个NSLog检查出来。 标签似乎没有被初始化。 任何想法? @interface AskerViewController() <UITextFieldDelegate> @property (weak, nonatomic) IBOutlet UILabel *questionLabel; @property (weak, nonatomic) NSString *question; @end @implementation AskerViewController @synthesize questionLabel = _questionLabel; @synthesize question = _question; – (void)setQuestion:(NSString *)question { _question = question; self.questionLabel.text = question; NSLog(@"label is %@", self.questionLabel); } @end NSLog的结果是: 2012-07-31 01:56:45.177 Kitchen Sink[23931:f803] label is (null)