How do you implement the makeKeyAndOrderFront: method?

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

Here is the code I already opened to open the window:

File 1 (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 (Action Open 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 was suggested by a friend to solve the problem with opening a window.

0


a source to share


3 answers


Somewhere after [preferenceController showWindow:self];

:

[self.window makeKeyAndOrderFront:self];

      



or did you mean to add a method to the controller?

// you should use a different method name, cause it not the
// controller that is made key and ordered front.
- (void)makeKeyAndOrderFront:(id)IBAction {
    [self.window makeKeyAndOrderFront:self];
}

      

+2


a source


You don't want to embed -makeKeyAndOrderFront:

, you want to call it in your window to bring it to the front and make it the key window. What does your method showWindow:

do?



+4


a source


The message is makeKeyAndOrderFront

sent only after the start of the main event loop [NSApp run]

. You can try to send a message from the main view by executing the method viewWillDraw

:

- (void)viewWillDraw
{
    [window makeKeyAndOrderFront: nil];
}

      

0


a source







All Articles