How to use NSWindowController to display a window in a standard application?

I created a new empty standard application using the Xcode template. The window in MainMenu.xib is removed, and I created a new customized subclass of NSWindowController with xib.

They were named "WYSunFlowerWindowController.h" and "WYSunFlowerWindowController.m".

And I add the init function as shown below:

- (id)init
{
    NSLog(@"init()");

    return [super initWithWindowNibName:@"WYSunFlowerWindowController" owner:self];
}

And my WYAppDelegate.m file looks like this:

static WYSunFlowerMainWindowController* windowController = nil;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    // Insert code here to initialize your application
    if (windowController == nil) {
        windowController = [[WYSunFlowerMainWindowController alloc] init];
    }
    [[windowController window] makeKeyAndOrderFront:windowController];
}

And I have a problem that the window cannot show it on its own after starting the application. Can anyone tell me why? Is there something wrong with my code?

I am new to Objective-C and cocoa. So I think that maybe I'm wrong, I can’t figure it out myself.

UPDATE:

Here is my project source. Please take a look and help me figure out what my mistake is.

https://dl.dropbox.com/u/3193707/SunFlower.zip

+5
1

init, , , , self super init.

-(id)init
{
    NSLog (@"init()");
    self = [super initWithWindowNibName:@"WYSunFlowerWindowController" owners:self];
    return self;
}

Edit

makeKeyAndOrderFront: [windowController showWindow:self]

, , xib, , WYSunFlowerWindowController IBOutlet ( NSWindowController) .

2:

@property @synthesize . get seters, .

+2

All Articles