Panel not shown after close


I have a strange behaviour with the panel: after running the application, when using “Preferences” for the first time the panel is shown and the controls are fine. But if I close the panel and then try to choose again “Preferences” from the menu the panel does not show up anymore.

Here is the Console after the first “Preferences”:

2011-12-13 23:49:42.771 RaiseMan[7164:707] showing <PreferenceController: 0x10019adf0>
2011-12-13 23:49:42.786 RaiseMan[7164:707] Nib file was loaded

Here is the Console after the second “Preferences”:

2011-12-13 23:50:59.044 RaiseMan[7164:707] showing <PreferenceController: 0x10019adf0>

I’ve checked the panel’s attributes in the NIB file, but that doesn’t seem to change anything.


The output you are seeing in the log is correct. The NIB file only loads once, so the message about the file loading only appears once.

I am not sure why the window doesn’t actually show on the second and subsequent invocation, but I would place some break points along the execution path starting in the -showPreferencePanel:sender method in the AppController.m file, then follow it along on the first and subsequent invocations to see where the differences are.


Are you calling [preferenceController showWindow:self]; at the end of showPreferencePanel:?


I’m using the following code in the showPreferencesPanel:

- (IBAction)showPreferencesPanel:(id)sender { if (!_preferenceController) { _preferenceController = [[PreferenceController alloc] init]; } NSLog(@"showing %@", _preferenceController); [_preferenceController showWindow:self]; }

The NSLog statement gets printed in the Console, indicating that the method is indeed executed. I’ve also put a breakpoint at the start of the method and everything seems to be ok. According to the Console the pointer to _preferenceController is the same. The only problem seems to be in the showWindow:self.

Very frustrating…




Hmm, that all sounds good. Do you see any log output in the console that would indicate there’s an exception being thrown?



No, here is the console after launching the program, calling the first time the Preferences, closing it and calling it again (the code from the susequent chapters is also already implements - hence the messages around the defaults):

[Switching to process 8874 thread 0x0] 2011-12-16 17:42:45.724 RaiseMan[8874:707] registered defaults: { BNREmptyDocumentFlag = 1; BNRTableBackgroundColor = <62706c69 73743030 d4010203 04050615 16582476 65727369 6f6e5824 6f626a65 63747359 24617263 68697665 72542474 6f701200 0186a0a3 07080f55 246e756c 6cd3090a 0b0c0d0e 5624636c 6173735c 4e53436f 6c6f7253 70616365 554e5352 47428002 10014631 20312030 00d21011 12135a24 636c6173 736e616d 65582463 6c617373 6573574e 53436f6c 6f72a212 14584e53 4f626a65 63745f10 0f4e534b 65796564 41726368 69766572 d1171854 726f6f74 80010811 1a232d32 373b4148 4f5c6264 666d727d 868e919a acafb400 00000000 00010100 00000000 00001900 00000000 00000000 00000000 0000b6>; } 2011-12-16 17:42:45.749 RaiseMan[8874:707] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to /var/folders/kg/xrljlfcd7qg16mxpjh2lmp6h0000gn/T/ 2011-12-16 17:42:45.759 RaiseMan[8874:707] applicationShouldOpenUntitledFile: 2011-12-16 17:42:45.760 RaiseMan[8874:707] Registered with notification centre 2011-12-16 17:45:31.719 RaiseMan[8874:707] showing <PreferenceController: 0x1003a8720> 2011-12-16 17:45:31.819 RaiseMan[8874:707] Nib file was loaded 2011-12-16 17:45:43.194 RaiseMan[8874:707] showing <PreferenceController: 0x1003a8720>

I’ve noticed a warning in the interface builder for the Preferences.xib:

“Content rectangle not entirely on screen with the menu bar”

But the first time the panel is shown is nicely on the screen and I can access the controls.



I cannot say for sure, but this line in the above seems to point to something significant: [color=#FF0000]applicationShouldOpenUntitledFile:[/color]


I’m not too concerned about applicationShouldOpenUntitledFile: – that’s just part of the application startup.

I am somewhat concerned by the Preferences.xib warning, however. Your best option may be to try replacing your Preferences.xib with the Preferences.xib from the solutions, as long as you used the same names for everything. Or just move Preferences.xib aside and start from scratch. That would tell us whether it’s a problem with an errant xib setting, or something in the code.

You could of course try to fix the warning, but those can be tricky to decode. And it may not be the actual problem.



I’m so stupid… The panel was not connected to the “window” outlet of PreferenceController… So elementary.

Thanks for the patience.



Oh no! :slight_smile: That’s okay. It can be easy to miss connections. I imagine that your window was appearing the first time because “Visible At Launch” was checked. Glad you got it figured out!