macosnswindownscontrol

Unresponsive UI Elements after closing NSWindow


Last week I spent a good amount of time fiddling around with the following problem. I solved it but since I couldn't find an answer here and I want to share my solution for anybody who runs into this.


Problem: My application runs in the background (menubar) and its main NSWindow contains all the preferences of my application. You close the NSWindow by clicking the close button in the top-left. After closing the NSWindow and reopening it, all the NSControls were not visually responding. The actions worked accordingly, but they where not updating.

I tried the following:

I'll post my solution below for the records.


Solution

  • My solution to this problem was to subclass NSWindow and overwrite the following methods:

    - (void)performClose:(id)sender{
        [self orderOut:nil];
    }
    
    - (void)close{
        [self orderOut:nil];
    }
    

    Now the NSWindow is hidden / ordered out and you just have to order it back in when displaying it.