Re: Getting reference to a window
Re: Getting reference to a window
- Subject: Re: Getting reference to a window
- From: Cocoader <email@hidden>
- Date: Fri, 3 Oct 2008 20:41:38 +0100
Thank you Shawn!
Your explanation was very clear. I have always had doubts around what
the First Responder did in a NIB/XIB. I understood that NSResponder
worked its way up the chain looking for something to handle the event,
I guess my knowledge is weakest when it comes to Interface Builder.
it's working a treat now and that's only 4 days of researching and
messing about that's come to an end!!
Cheers matey, that's a drink for you if you're at the monthly meeting :)
--
Paul Harvey
Hiddenfield Software
www.hiddenfield.com
On 3 Oct 2008, at 19:06, Shawn Erickson wrote:
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