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:19:53 +0100
You, sir, are a Super Hero!
I have spent a lot (and I mean a LOT) of time over this, reading
books, looking at other projects, scouring the mailing list archives.
I knew from my experiments that it was something wrong with the way my
project was set up, not a problem with the code itself.
You have switched a light on in my brain by your statement:
If you want your main menu to be able to send messages to a
document, you need to connect their actions to the First Responder
icon within your xib. The front-most document will be the first
responder to that message so it'll receive it. Read this for more
information:
I have read so much about First Responder within a NIB/XIB and somehow
couldn't quite work out what it was, as if it was some ever changing
thing. Now it makes sense!!!
THANK YOU!!!!!!!
--
Paul Harvey
Hiddenfield Software
www.hiddenfield.com
On 3 Oct 2008, at 19:06, I. Savant wrote:
On Fri, Oct 3, 2008 at 9:57 AM, Cocoader <email@hidden>
wrote:
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.
Yes, because the "File's Owner" of that xib instance is your
HF_Browser and its connections are restored when a new document is
instantiated (and a new copy of your XIB's object graph is
'awakened').
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.
Why do you do this? You're only creating an instance of your
document object (without allowing Cocoa to open a copy of the xib and
restore connections). All you have is a lone instance of your
NSDocument subclass.
Re-read this document:
http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/Documents.html#/
/apple_ref/doc/uid/10000006
See below for the right way to do this.
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. Can you please advise?
Your code is called because you have a valid instance of your
document subclass. Because it was not correctly created by Cocoa's
document machinery, none of its outlets (including "window") are
connected to anything.
If you want your main menu to be able to send messages to a
document, you need to connect their actions to the First Responder
icon within your xib. The front-most document will be the first
responder to that message so it'll receive it. Read this for more
information:
http://developer.apple.com/documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/chapter_2_section_6.html#
--
I.S.
_______________________________________________
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