On Mar 2, 2010, at 6:53 PM, Steven Degutis wrote:

> Few simple steps:
> 
> (1) Create a subclass of NSWindowController and override -init to call
> super's -initWithWindowNibName:, passing something like @"MyWindow"
> (2) Create a XIB file with the filename called MyWindow
> (3) Change File's Owner to your recent subclass
> (4) Connect the -window outlet of your subclass to the NSWindow in the XIB
> file
> (5) Instantiate your subclass somewhere and either access -window directly
> or call -showWindow: (which is what I usually do)
> 
> -Steven
> 
> On Tue, Mar 2, 2010 at 9:13 PM, William Squires <wsqui...@satx.rr.com>wrote:
> 
>> Please help, I'm still a bit fuzzy on how to open a window in Cocoa/ObjC. I
>> realize there's a correlation between a nib, the window you design(ed) in
>> IB, and the .h/.m files for the controller class, but how do you actually
>> USE this stuff? i.e. If I wanted to make a window in REALbasic, I would
>> design the window's UI, put in a publicly accessible Display() method that
>> did something like:
>> 
>> Public Sub Display()
>> // Setup control's states based on available info (this window's class'
>> properties)
>> Me.Setup()
>> 
>> // This is a modal window to allow the player to roll a new
>> player-character
>> Me.ShowModal()
>> End Sub
>> 
>> Then, somewhere else, I would do:
>> 
>> Dim w As wndRollNewPC
>> Dim theNewPC As PlayerChar
>> 
>> theNewPC = nil
>> w = New wndRollNewPC()
>> w.DefaultPlayerName = "<untitled PC>"
>> w.UseDefaultRules = True
>> w.Display()
>> theNewPC = w.NewPC
>> w = nil
>> If (theNewPC = nil) Then
>> // Player somehow aborted
>> Exit Sub
>> End If
>> ...
>> 
>> 
>> And the call "w.Display() would make the window visible and frontmost (or,
>> in Cocoa terms, it would load the nib, then - somehow - make it (the window,
>> not the nib!) visible, and set one of the controls to be FirstResponder. It
>> would also hook up the FilesOwner proxy object reference.)
>> What I want to know is how to get this bit of magic to work? Am I going to
>> have to chant arcane phrases over my keyboard while moving my mouse just so?
>> :) This gets even more confusing on the iPhone, BTW.
>> 
>> 
>> A compiler is a tool for turning source code into error messages;
>> generating machine language bytes is just a fortuitous by-product!
>> 
> 
> 
> 
> -- 
> Steven Degutis
> http://www.thoughtfultree.com/
> http://www.degutis.org/

You may wish to connect the window's delegate outlet in the xib/nib to the 
window controller (file's owner) object, as well--as a sort of inverse to the 
window outlet--so that window delegate notifications can be received by the 
window controller.

-- Andrew_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to