所以我有一个设置整数的方法:-(void)setcurrentviewfromint:(int)currentint{
它在一个名为MyView
. 从我的viewDidLoad
方法中,我调用它,并将其设置为 1:
currentview
是 int 类型,在我的头文件中创建
- (void)viewDidLoad
{
[super viewDidLoad];
MyView *myview = [[MyView alloc]init];
[myview setcurrentviewfromint:1];
}
然后,在 中MyView.m
,我有这些课程:
-(void)setcurrentviewfromint:(int)currentint{
currentview = currentint;
NSLog("currentviewis:%d",currentview);
[self setNeedsDisplay];
}
- (void)drawRect:(CGRect)rect {
NSLog(@"drawRectCalled");
if (currentview == 1) {
NSLog(@"do something here");
}
}
}
但是调试器会打印出:
2012-07-18 18:02:44.211 animation[76135:f803] currentviewis:1
2012-07-18 18:02:44.223 animation[76135:f803] drawRectCalled
但不打印“在这里做点什么”。任何想法为什么currentview
不等于1?