Re: Two controllers in a window, how do I get one to run a function in another?
Re: Two controllers in a window, how do I get one to run a function in another?
- Subject: Re: Two controllers in a window, how do I get one to run a function in another?
- From: Graham Cox <email@hidden>
- Date: Tue, 1 Sep 2009 15:14:16 +1000
On 01/09/2009, at 2:55 PM, BareFeet wrote:
Doh!, no, missed that. Thanks for that.
That's important - it's a forward declaration, which informs the
compiler that the MyDocument* is merely a pointer, and so it
doesn't need to know anything else about the class - it has all it
needs to proceed to lay out this object.
Again, I'd like to see where this is documented, in the context of
linking controllers. Thanks so much for the tip.
Well, it isn't specifically documented in that context, as it's a
generic feature of the Objective-C language, used for the purpose I
described - namely, to avoid a dependency between headers when all
that the compiler really needs to know at that point is the pointer
size. Most other languages have similar features.
Well, have you actually linked it to the instance of MyDocument? If
these objects exist as part of the nib (which is the simplest
approach) then you link them together in Interface Builder by ctrl-
dragging from one to the other. In the case of the document class,
it's "File's Owner" in the nib. The other controller would
typically be dragged in as an NSObject (blue cube icon) and have
its class set to MyController. IB will display the outlets
"the_document" and "the_controller" and then it's up to you to
connect them.
Yes, I've done that, control dragged from MyController to File's
Owner and selected the_document. For simplicity, I'm just creating
the_document in MyController (I've no need for MyDocument to refer
to the_controller).
I still get nil for the_document at runtime.
OK, my antennae are twitching. You're going to have to show your code,
because it sounds like you're doing something very strange here.
You say you're creating the document in your controller. Huh? I could
just about imagine the other way around would be OK, but this?
Nooo..... The document is created for you by NSDocumentController, and
that in turn uses your info.plist to find out what class of document
is needed for what types of file. The document then loads the
associated nib, and becomes File's Owner. You will not be creating a
document anywhere - it's invariably done for you. Realise that the
objects in a nib are real - you don't have to instantiate them in your
code - doing so is an error. The objects are instantiated when you
drag them into the nib window in IB.
The document might then own the controller, and that would be either
instantiated in the nib (by far the simplest approach) or in your code
and hooked up manually. Sound like something somewhere is seriously
bass-ackwards...
Post the code where you create the document.
--Graham
_______________________________________________
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