Domanda

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:

  • Unchecking "Release on close" in IB for NSWindow
  • Reloading NSWindow from NIB
  • Strong references for all NSControls
  • Calling "Become first responder" on NSControls
  • Reloading all the parenting NSViews
  • Implementing all the delegates hooking up each NSControl (Worked for NSControl, but was way too much work to use it for each and every one)
  • Disabling and then reenabling the NSControls

I'll post my solution below for the records.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top