I have a custom NSView object with a retained property named bgColor. I override the setter method by defining setBgColor method:
- (void)setBgColor:(NSColor *)theColor
{
[bgColor autorelease];
bgColor = [theColor retain];
[self setNeedsDisplay:YES];
}
I also have another function called isOnline:
-(void)isOnline:(BOOL)connected{
if(connected){
self.bgColor = onlineBackgroundColor;
} else {
self.bgColor = offlineBackgroundColor;
}
}
When I called the isOnline method in initWithFrame method using [self isOnline:NO]
, it works fine. But when I try to call isOnline method from a controlling object with:
[theCustomedView isOnline:YES];
or theCustomedView.isOnline = YES;
It would crash in the setBgColor method at the line: bgColor = [theColor retain];
The complier complains Program received signal: "EX_BAD_ACCESS". I can't figure out why. Was that autorelease wrong?
If so, how come I can call from the controlling object [theCustomedView setBgColor:aColor];
and from self in the initWithFrame and it would work fine?
Any ideas?