Close NSColorPanel


#1

Hi,

I was wondering how you closed the NSColorPanel programatically upon closing the Preferences window?

I’ve tried to subclass the NSColorWell and fire up the NSCOlorPanel with [[NSColorPanel sharedColorPanel] makeKeyAndOrderFront:self]; which seems to work well. But upon picking, it makes no difference.

I did try to use [[NSColorPanel sharedColorPanel] setTarger:self] (in the NSColorWell subclass, but that makes no difference.

Any pointers?

Cheers,

Adrian


#2

Just to add that I’ve resolved this.

After doing some research in the NSColorPanel class, it appears that usually there is only one ‘shared’ ColorPanel per Application (note usually, dependson the app). I managed to resolve the issue by doing this:

-(IBAction)changeBackgroundColor:(id)sender{
    NSColor *color = [colorWell color];
    NSLog(@"Color changed: %@", color );
    [[NSColorPanel sharedColorPanel] orderOut:nil];
    [colorWell deactivate];
}