0

I have a single window MacOS X application.

I'm having some problem understanding how to connect some parts of the MainMenu.xib NIB file.

What I need to do is to be able to do some stuff in MainMenu's (void)windowDidLoad function. I just don't know how to connect the MainMenu.xib file to a .m file.

I created a NSObject file in the NIB file which I then connected to a file called MainController and do a lot of stuff there that works.

EDIT

OK, to clearify my question:
Let's say I create a new Project (I'm using Xcode 4.3.2).
I choose File > New > Project, there I choose Mac OS X > Application > Cocoa Application
I press next, set the Product Name as Awesomesauce, uncheck all of the check boxes, press Next and finally choose a folder to store my project in.

I now have 3 files AppDelegate.h, AppDelegate.m and MainMenu.xib (I also have some stuff in the Supporting Files folder which I don't think I need to think about).

I want to have a NSWindowController file that I can connect to to MainMenu.xib. I create a new file (Objective-c Class > NSWindowController) and name it MainMenuController.

Now I open the MainMenu.xib, choose File's Owner under Placeholders and under the Identity Inspector I set the Custom Class > Class as MainMenuController.

Righ clicking File's Owner I create a connection between window and Window - Awesomesauce.
I also add <NSApplicationDelegate> to MainMenuController.h and create a connection between Window - Awesomesauce delegate and File's Owner

At this time my MainMenuController looks like this:

@implementation MainMenuController

- (id)initWithWindow:(NSWindow *)window
{
    self = [super initWithWindow:window];
    if (self) {
        NSLog(@"Initializing MainMenuController");
    }

    return self;
}

- (void)windowDidLoad
{
    [super windowDidLoad];
    NSLog(@"Window did load");
}

- (void)windowWillLoad{

    NSLog(@"Window will load");

}
@end

When I run my application I get the Awesomesauce window but none of the NSLog's logs anything. That includes the NSLog in the init method.

What am I doing wrong?

Bjorninn
  • 4,027
  • 4
  • 27
  • 39
  • Have you looked at the current *File's Owner* of the MainMenu from within Interface Builder? Isn't is your App Delegate? – trojanfoe Apr 16 '12 at 18:24
  • What documentation have you looked at? – Rob Keniger Apr 17 '12 at 06:14
  • The File Owner was set as NSApplication, I tried to change that to a NSWindowController class I have but that does nothing. XCode has a setting under Target called "Main Interface" where my MainMenu is selected. None of my classes have been able to receive the windowDidLoad call. What connections have to be made for the Window in MainMenu to send a windowDidLoad call? @Rob I've googled alot. I ran into this: http://stackoverflow.com/questions/2695671/nswindowcontroller-windowdidload-not-calledand tried something like it. But no luck – Bjorninn Apr 17 '12 at 11:15
  • 1
    Why do you need `windowDidLoad`? Can't you use `ApplicationDidFinishLaunching`? What exactly do you want to do; you haven't explained. – trojanfoe Apr 17 '12 at 14:59
  • 1
    I think there are several things wrong here -- first, you've created a window controller class, but you never call alloc initWithWindow: on it to instantiate the class (you could do that in your app delegate). Second, windowDidLoad isn't called because the window is loaded as part of the nib loading process, not by the controller. As @trojanfoe said, you should define a little better what you're trying to do. – rdelmar Apr 17 '12 at 17:01
  • I have some settings from NSUserDefaults that I load and then set some UI items depending on those. There's a, e.g., NSPopUpButton button I need to set to a specified index. And yes I see by running a quick check that I can use ApplicationDidFinishLaunching. Thanks a lot, Cheers! – Bjorninn Apr 17 '12 at 17:51

0 Answers0