I am creating a app from a tutorial in a book, but I noticed a problem, when the preference window i created is opened and then closed it won't open again, how can i fix this?
Thanks.
EDIT: I saw another post about this but was still un-answered, so i was wondering if you could answer this for me.
EDIT: I am talking about a panel (used a preference pane), it is being opened via a Menu item, and is closed with the cross in the corner of the window. The code I used to create it was from the Book, Cocoa Programming For Mac OS X, the Panel which is being used as a preference pane is in a separate nib file.
EDIT: Here's the code, it's complicated as the tutorial made you create 4 files.
1) Preferences_Delegate.h
#import <Cocoa/Cocoa.h>
@class PreferenceController;
@interface Prefernces_Delegate : NSObject {
PreferenceController *preferenceController;
}
- (IBAction)showPreferencePanel:(id)sender;
@end
2) Preferences_Delegate.m
#import "Prefernces_Delegate.h"
#import "PreferenceController.h"
@implementation Prefernces_Delegate
- (IBAction)showPreferencePanel:(id)sender
{
// Is preferenceController nil?
if (!preferenceController) {
preferenceController = [[PreferenceController alloc] init];
}
NSLog(@"showing %@", preferenceController);
[preferenceController showWindow:self];
}
@end
3) PreferencesController.h (Not Important)
#import <Cocoa/Cocoa.h>
@interface PreferenceController : NSWindowController {
IBOutlet NSButton *checkbox;
}
- (IBAction)changeNewEmptyDoc:(id)sender;
@end
4) PreferencesController.m
#import "PreferenceController.h"
@implementation PreferenceController
- (id)init
{
if (![super initWithWindowNibName:@"Preferences"])
return nil;
return self;
}
- (void)windowDidLoad
{
NSLog(@"Nib file is loaded");
}
- (IBAction)changeNewEmptyDoc: (id)sender
{
int state = [checkbox state];
NSLog(@"Checkbox changed %d", state);
}
@end