I have been seeing some strange behavior when I try to access a class variable or a property in my drawRect method..
In my .h file I have the following
@interface DartBoard : UIView
{
Board * board;
int index;
}
@property (readwrite, assign, nonatomic) NSNumber * selectedIndex;
@end
In my .m file I have the following
@implementation DartBoard
@synthesize selectedIndex;
-(id)init
{
self.selectedIndex = [NSNumber numberWithInt:5];
index = 123;
return self;
}
- (void)drawRect:(CGRect)rect {
NSLog(@"selectedIndex: %d",[self.selectedIndex intValue]);
NSLog(@"index: %d",index);
}
@end
the output is
2012-06-12 19:48:42.579 App [3690:707] selectedIndex: 0
2012-06-12 19:48:42.580 App [3690:707] index: 0
I have been trying to find a solution but have had no luck..
I found a similar question but there was no real answer to the issue
See: UIView drawRect; class variables out of scope
I have a feeling drawRect is different that normal methods and is not getting the scope of the class correctly but how do I fix it?
Cheers Damien