I've just started working with Cocoa and Objective-C and have been following along the second edition of Cocoa Programming for Mac OS X. I'm working in Xcode 3 instead of 2.5 so I've had to work around that a bit, but for the most part I've been fine. However, for the life of me I can't get a Preference panel to work correctly.
PreferenceController is a class that extends NSWindowController. The interface is being loaded from Preference.nib. This is the init method I have in PreferenceController:
And here is what I am doing to actually load the window. (This is in AppController):
I know showPreferencePanel is being called because I get the NSLog message. The first time the preference button is pressed since the application is loaded it works perfectly. However, once it is closed and you try again nothing happens. I added a check to export to the log to see if the window is loaded, and it says it is, even when it does not show. Shouldn't showWindow just show the window if it has been loaded? Is there some method I need to override that I'm not?
If I comment out the [preferenceController showWindow: self] line I get the exact same behavior, which suggests that it is doing nothing. If you uncheck "Visible at launch" in IB then it is never displayed.
I'm sure I'm missing something really dumb, but I just can't figure out what that is.
PreferenceController is a class that extends NSWindowController. The interface is being loaded from Preference.nib. This is the init method I have in PreferenceController:
Code:
- (id) init
{
self = [super initWithWindowNibName:@"Preferences"];
return self;
}
And here is what I am doing to actually load the window. (This is in AppController):
Code:
- (IBAction) showPreferencePanel: (id) sender
{
NSLog(@"Showing Preferences");
//Is preferenceController nil?
if(!preferenceController)
preferenceController = [[PreferenceController alloc] init];
[preferenceController showWindow: self];
}
I know showPreferencePanel is being called because I get the NSLog message. The first time the preference button is pressed since the application is loaded it works perfectly. However, once it is closed and you try again nothing happens. I added a check to export to the log to see if the window is loaded, and it says it is, even when it does not show. Shouldn't showWindow just show the window if it has been loaded? Is there some method I need to override that I'm not?
If I comment out the [preferenceController showWindow: self] line I get the exact same behavior, which suggests that it is doing nothing. If you uncheck "Visible at launch" in IB then it is never displayed.
I'm sure I'm missing something really dumb, but I just can't figure out what that is.