OSX: loadView doesn't execute

375 views Asked by At

I've done some iOS coding but right now I'm trying to write a Mac App. This link: viewDidLoad in NSViewController? says that the OSX equivalent of viewDidLoad is loadView. I want to call an initalizing method as soon as the view appears, but loadView doesn't seem to be executing; that is, the following code in my view controller:

- (void)loadView {
    [super loadView];
    NSLog(@"Test");
    [self addPanGesture];
}

Doesn't seem to do anything. The NSLog never displays and the method addPanGesture never executes. Am I missing something really stupid or is loadView no longer the proper method to override?

EDIT: I switched to windowDidLoad and removed the super call per Ahmed Z's advice, but this doesn't work either. Do I have to do anything other than simply add the method like in iOS? Also, the link I orignially posted at the top seems to say in the "accepted" answer (not the highest rated one) that windowDidLoad is no longer used as of Mac OSX 10.5

EDIT 2: It also seems worth mentioning that I'm using a xib file. One stackoverflow link said that loadView was called only when programmatically setting up a view.

1

There are 1 answers

0
OneTimeShot On BEST ANSWER

Figured it out. By putting another NSWindow in my MainMenu.xib and creating a reference for it I was able to call

[self.secondWindow display];

to open a second window.