Question

I am developing a small and simple status menu application.
There is a menu and when the user clicks on it, a HUD window (NSPanel) should appear. This is how I show the panel:

[hudWindow makeKeyAndOrderFront: self]; 

This is how I dismiss the window:

[hudWindow orderOut: nil];

So that's the events chain:

  1. When the app starts I dismiss the window;
  2. Then the user (that's me :-)) clicks on the menu item and makes the panel appear;
  3. Then I click on the x and close the panel;
  4. Then I click again on the menu item and the window doesn't appear again.

It doesn't appear again probably because it gets deallocated, and I have put a weak storage, otherwise with __unsafe_unretained it would crash at the second launch.
So I'm guessing if there's a way to avoid deallocating the window when the user clicks on it.
I have tried with a strong storage but this case at the second launch I'm unable to close it again and that's a problem.
There are many menu status applications that are able to display a window without that the user can "kill" it, I would make something of similar.

Was it helpful?

Solution

You should uncheck the "Release When Closed" checkbox in IB (or done the equivalent in code). That box is checked by default for panels.

Using a strong pointer probably doesn't work because the releasedWhenClosed setting overrides that. Having a strong pointer just means that the retain count will be at least one, but that doesn't prevent the system from explicitly sending a release message to the panel.

OTHER TIPS

Can't you just change your property from weak to strong?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top