Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

makeKeyAndOrderFront only does the latter

Tags:

cocoa

nswindow

I am trying to open one window from another using makeKeyAndOrderFront. The new window appears, but does not receive focus.

The code for the main window is:

#import "SecondWindowController.h"
@implementation FirstWindowController
-(IBAction)showSecondWindow:(id)sender
{
  if (!secondWindowController)
    secondWindowController = [[SecondWindowController alloc] init];
  [[secondWindowController window] makeKeyAndOrderFront:self];
}

SecondWindowController is a NSWindowController, as follows:

@implementation SecondWindowController
-(id)init
{
  if (![super initWithWindowNibName:@"SecondWindow"])
    return nil;
  return self;
}

I've also tried putting [secondWindowController showWindow:self] before the makeKeyAndOrderFront but it doesn't make a difference.

like image 699
mattdwen Avatar asked Dec 06 '22 04:12

mattdwen


2 Answers

Did you make sure the window outlet for SecondWindowController is hooked up to the window in your NIB? The window could be displayed just by loading the NIB, even if the outlet is not hooked up.

like image 123
Doug Richardson Avatar answered Dec 18 '22 05:12

Doug Richardson


Are you using a borderless window? If so you need to override canBecomeKeyWindow and return YES

like image 22
Leibowitzn Avatar answered Dec 18 '22 03:12

Leibowitzn