iOS塞特吸气剂
我试图给recordingStatus赋值- ie记录状态=1 但是它没有进入setter,我需要一些自定义代码。。我的代码怎么了 谢谢 码头 在file.h中iOS塞特吸气剂,ios,setter,getter,synthesize,Ios,Setter,Getter,Synthesize,我试图给recordingStatus赋值- ie记录状态=1 但是它没有进入setter,我需要一些自定义代码。。我的代码怎么了 谢谢 码头 在file.h中 @property (strong, nonatomic) IBOutlet UILabel *recordingStatusText; @property (nonatomic)int recordingStatus; .... 在file.m中 /* -------------------- Property Setter and
@property (strong, nonatomic) IBOutlet UILabel *recordingStatusText;
@property (nonatomic)int recordingStatus;
....
在file.m中
/* -------------------- Property Setter and Getters ----------------------*/
@synthesize recordingStatus;
- (int) getRecordingStatus {
return recordingStatus;
}
- (void) setRecordingStatus:(int)status
{
[_recordingStatusText setText: @"Just testing!"];
recordingStatus = status;
}
你能把你调用setter的代码显示出来吗?我假设您通过以下操作直接访问ivar(假设您的ivar名为recordingStatus): 相反,请尝试以下方法:
self.recordingStatus = 1
你能把你调用setter的代码显示出来吗?我假设您通过以下操作直接访问ivar(假设您的ivar名为recordingStatus): 相反,请尝试以下方法:
self.recordingStatus = 1
要设置和获取属性,应使用
self.property=newValue代码>
覆盖setter和getter
对于getter,不需要在方法签名中写“get”。因此,getter方法使用了错误的名称。如果要重写它,则该方法应为
-(int) recordingStatus {
// Custom Getter Method
return _recordingStatus;
}
在int
s的情况下,Objective-c希望以
-(void)setValue:(int)newValue;
-(int)value;
要设置和获取属性,应使用self.property=newValue代码>
覆盖setter和getter
对于getter,不需要在方法签名中写“get”。因此,getter方法使用了错误的名称。如果要重写它,则该方法应为
-(int) recordingStatus {
// Custom Getter Method
return _recordingStatus;
}
在int
s的情况下,Objective-c希望以
-(void)setValue:(int)newValue;
-(int)value;
仅供参考:getter不是从一个get
开始的是的,我就知道,对不起!仅供参考:getter不是从一个get
开始的是的,我就知道,对不起!self.property=newValue就是它,感谢您的详细回答,非常感谢!self.property=newValue就是它,感谢您的详细回答,非常感谢!