Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Spawning windows.



> What
> would I do to make the window be displayed? What would the Cocoa code look
> like to do this?

OK, seems you're having a bit of hard time figuring out how the various
pieces can fit together, so here's one sample way to open a new instance of
an arbitrary window from a nib file (many other variations possible,
depending on how you organize your project):

- You create a nib "MyWindowNib" to describe the window and its layout.

- You create the MyWindowController class show below, and drag
MyWindowController.h into the nib file so it knows about the class.

- There should be an instance of MyWindowController in the nib with the
window. Its window outlet should be connected the the window, and the
window's delegate outlet should be connected to it.

- In the simple case where you have just one window in the nib, don't create
a new instance of MyWindowController, just set the file's owner object's
custom class to MyWindowController.


@interface MyWindowController : NSWindowController
{
}

+ ( MyWindowController *) createAndShowWindow;

@end


@implementation MyWindowController

+ ( MyWindowController *) createAndShowWindow
{
    MyWindowController  * wdw = [[ MyWindowController alloc] _init];
    [[wdw window] makeKeyAndOrderFront: self];
    return wdw;
}

- (id) _init
{
    self = [super initWithWindowNibName: @"MyWindowNib" owner: self];
    return self;
}


-- 
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 722-0567 voice


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

References: 
 >Re: Spawning windows. (From: "George C" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.