UIView drawRect; class variables out of scope
- by Toby Wilson
Short & sweet version of my last question in light of new information.
I have a UIVIew with an init and a drawrect method (and another thread and a bunch of other stuff, but I'll keep it short & sweet).
All of the class variables that I alloc and init in the -(id)init method are out of scope/nil/0x0 in the drawRect method, and I am unable to access them.
For example;
In the interface:
NSObject* fred;
In the implementation:
-(id)init
{
if(self == [super init])
{
fred = [[NSObject alloc] init];
}
return self;
}
-(void)drawRect:(CGRect)rect
{
NSLog(@"Fred is retained %i times",[fred retainCount]); //FAIL
NSLog(@"But his variable is actually just pointing at uninitialised 0x0, so you're not reading this in the debugger because the application has crashed before it got here."
}
Should add that init IS being called before drawRect also. Anyone have any ideas?