-1

I have a window that I am creating based off of clicking a row in a Tableview, instantiated like such:

HKLUserProfileController *userProfileController = [[HKLUserProfileController alloc] initWithNibName:@"HKLUserProfileController" bundle:nil];

_wc =[[NSWindowController alloc] initWithWindowNibName:@"HKLProfileWindowController"];
[_wc.window.contentView addSubview:userProfileController.view];

    // other extraneous stuff here

[_wc showWindow:self];

if([_wc.window canBecomeKeyWindow]) {
    [_wc.window makeMainWindow];
    [NSApp activateIgnoringOtherApps:YES];
    [self makeKeyAndOrderFront:self];
}

This works, but I cannot seem to get the window to become the main/key/front window. I've tried:

... from this place where I am creating the WindowController, and also from inside viewDidLoad/loadView of the NSViewController whose View was added to the Window. No dice. (this is my ultimate goal here, so if you see something obvious i'm missing, please point it out).

So I realized that I should be trying to do this in the subclass of the WindowController itself... so I thought to put it in windowDidLoad, but no result. I set some breakpoints, and tried the other logical init methods, and to my surprise, NONE of them fire at all.

@implementation HKLProfileWindowController

- (void)windowDidLoad {
    [super windowDidLoad];
    // breakpoint here
}

-(void)awakeFromNib {
    // breakpoint here
}

- (id)init {
    // breakpoint here
    self = [super init];
    if (self) {
        // breakpoint here
    }
    return self;
}

@end

My xib is connected as an Outlet / Delegate to my File's Owner properly, as far as I can tell. This is leading me to believe this is the root of the problem, but for the life of me, I can't figure out what is the issue...

Thanks...

EDIT

I realize what is happening with the keyWindow - because it's coming from shouldSelectRow in the TableView, it IS becoming key on mouseDown events, but the first window - which holds the TableView - is becoming key again on mouseUp events... which is maddening!

Will search for solutions to that, but open to comments here!

(still can't figure out why the init methods are not firing though...

jesses.co.tt
  • 2,689
  • 1
  • 30
  • 49

1 Answers1

1

You use NSWindowController in your alloc/init line and you expect it to become an HKLProfileWindowController instance? Why?

You also need the File's Owner custom class set to HKLProfileWindowController but there's no reason to expect that's sufficient to get an HKLProfileWindowController instance when you ask for an NSWindowController. What you get is an NSWindowController and none of the subclass code is used.

I'll delete this answer if your code is from before you implemented the HKLProfileWindowController class, but given what you have pasted here, that's why your breakpoints don't get hit.

stevesliva
  • 5,351
  • 1
  • 16
  • 39