Hide child controls in an NSView

380 Views Asked by At

I have an NSView with multiple child controls in it. I know I can call [childControl setHidden:TRUE] but I was wondering if its possible to block the message "drawRect:" for the child controls.

Ive noticed that not calling [super drawRect:NSZeroRect] on the NSView does not affect the child controls. So my question is who calls the child controls drawRect message? And if there is a way to block it.

Thanks, Jose.

1

There are 1 best solutions below

0
On BEST ANSWER

Every time the controls should react optically, they draw its view again. If you really want to solve this problem like that, you can create for each control a subclass and add a code like this:

-(void)drawRect:(NSRect)rect {
if (!self.blocked) {
[super drawRect:rect];
}
}

The property "blocked" is a boolean which you have to set to YES or NO if you want to block it. Note: To totally hide it the control subclass has to be blocked before it draws it self the first time.