views:

341

answers:

2

I am making a new window open and would like to implement the method makeKeyAndOrderFront: for the window, i was wondering what code i would need to enter to do this.

Here is some of the code I've already got to open the window:

File 1 (The First Controller)

#import "PreferenceController.h"


@implementation PreferenceController

- (id)init
{
    if (![super initWithWindowNibName:@"Preferences"])
     return nil;
    return self;
}
- (void)windowDidLoad
{
    NSLog(@"Nib file is loaded");
}

File 2 (The Action Opening The Window)

#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];
}

The reason I am trying to do this is it has been suggested by a friend to solve a window opening problem.

+4  A: 

You don't want to implement -makeKeyAndOrderFront:, you want to call it on your window in order to bring it to front and make it the key window. What does your showWindow: method do?

Martin Gordon
Is shows the nib named "Preferences".
Joshua
+2  A: 

Somewhere after [preferenceController showWindow:self];:

[self.window makeKeyAndOrderFront:self];

or did you mean add a method to the controller?

// you should use a different method name, cause it's not the
// controller that is made key and ordered front.
- (void)makeKeyAndOrderFront:(id)IBAction {
    [self.window makeKeyAndOrderFront:self];
}
Georg
Do you mean after [self.window makeKeyAndOrderFront:self];} or before the } ?
Joshua