Re: Getting reference to a window
Re: Getting reference to a window
- Subject: Re: Getting reference to a window
- From: "Shawn Erickson" <email@hidden>
- Date: Fri, 3 Oct 2008 11:06:55 -0700
On Fri, Oct 3, 2008 at 6:57 AM, Cocoader <email@hidden> wrote:
> Hi there,
>
> My NSDocument 'HF_Browser' works with a window in a XIB file. From within
> this HF_Browser.m file I can get a reference to the window, set it's title,
> etc.
At runtime the framework (or code of your own) creates an HF_Browser
instance making it the owner of the xib file that contains the window
you describe. This instance is hooked up with the window, etc.
allowing it to message the UI.
> In MainMenu.xib I have a menu command, 'Jump To' (invoked with Cmd-J). I
> dragged an Object object into MainMenu.xid and set it to HF_Browser then
> connected the Jump To menu command to it, to an IBAction in HF_Browser.m.
By dragging an object into your MainMenu xib you are creating an
object instance (in this case an instance of HF_Browser). Then you
connect a menu item with that instance. At runtime when your MainMenu
xib is load an instance of HF_Browser is unarchived, one not
associated with any document and having no ownership of the xib
containing the window it is meant to manage.
> When I hit Cmd-J my method- (IBAction)MenuJumpTo:(id)sender is called
> perfectly but within this method I can't get any reference to the window at
> all.
Yup because the instance you created is not associated with any window
or document.
> Can you please advise?
Don't try to connect your menu item that way and remove the HF_Browers
instance you created in your main menu xib.
Review the concept of the responder chain since it existing for
exactly this type of situation...
http://developer.apple.com/documentation/Cocoa/Conceptual/CocoaFundamentals/CoreAppArchitecture/chapter_7_section_6.html
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden