So I have a method that sets an integer: -(void)setcurrentviewfromint:(int)currentint{ It is in a class called MyView. From my viewDidLoad method, I call it, and set it too 1:
currentview is of type int, created in my header file
- (void)viewDidLoad
{
[super viewDidLoad];
MyView *myview = [[MyView alloc]init];
[myview setcurrentviewfromint:1];
}
Then, in MyView.m, I have these classes:
-(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");
}
}
}
But the debugger prints out:
2012-07-18 18:02:44.211 animation[76135:f803] currentviewis:1
2012-07-18 18:02:44.223 animation[76135:f803] drawRectCalled
But doesn’t print “do something here”. Any ideas why currentview doesn’t equal 1?
First, about your question.
What datatype is currentview?
Second, it looks like your NSLog in setcurrentviewfromint: never gets called. If it was called, youd see “currentviewis:1” so make sure that is linking up correctly.
And, I must say, camel-case! Your method names are all lowercase and it’s hard to read. 🙂