【发布时间】:2012-09-28 02:00:20
【问题描述】:
我有一个在标题中提到的 ivar
@interface MyClass : UIView{
int thistone;}
- (IBAction)toneButton:(UIButton *)sender;
@property int thistone;
@end
并且我已经在实现中综合了它:
@implementation MyClass
@synthesize thistone;
- (IBAction)toneButton:(UIButton *)sender {
if(thistone<4)
{thistone=1000;} // I hate this line.
else{thistone=thistone+1; }
}
我找不到(或在任何手册中找到)设置非零初始值的方法。我希望它从 1000 开始,每次按下按钮时增加 1。该代码完全符合我的意图,但我猜有一种更合适的方法可以节省我上面的 if/else 语句。非常感谢代码修复或指向在线文档中特定行的指针。
【问题讨论】:
-
您应该使用 init* 方法。看到这个答案:stackoverflow.com/questions/4579342/…
标签: ios button synthesize