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: BareFeet <email@hidden>
- Date: Tue, 1 Sep 2009 14:55:46 +1000
Hi Graham and all,
ahh, now that makes sense. That's what I was missing. I was trying
to add IBOutlets for instance variables but needed to instead add
IBOutlets for the class (eg MyDocument).
Whaaa? You're probably getting your terminology confused
but the above makes no sense to me. IBOutlets *are* instance
variables. You don't/can't "add" an IBOutlet for an instance
variable. The presence of "IBOutlet" is merely a marker that allows
IB to parse the file. If you look up its definition you'll see it
evaluates to nothing.
Yes, bad terminology, sorry. I know IBOutlets are just a label/marker
for instance variables which Interface Builder recognises. What I
meant was that I was trying to add in MyController the IBOutlet label
for an instance variable in the MyDocument class, but should have
instead labeled an instance of the MyDocument class itself. I don't
know if that's any clearer.
You are also not adding an IBOutlet for the class. You are adding an
instance variable, tagged as an outlet, which will point to the
MyDocument instance.
Yes, that's what I meant ;-)
When I try to compile the above, I get an error:
expected specifier-qualifier-list before 'MyDocument'
If I change the "MyDocument*" to "id", it works, but what's the
problem?
Did you include the @class MyDocument; line?
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.
You can use id, which is a bit like void*, an anonymous type that
will shut the compiler up, but it's better to type things
specifically where you can do so, and here is one such place.
Yes, I'm familiar with id being like void, used as a non-specific
pointer etc. I prefer to use specific classes, but just used id
temporarily to isolate the problem. I've specified the type now that
the error is gone (thanks to @class).
In your code, you can now do things like this, from your controller:
NSString* file = [the_document fileString];
the_document is showing as value nil. It doesn't seem to be linked
to the instance of MyDocument. Am I missing something?
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.
Any other ideas?
Thanks,
Tom
BareFeet
_______________________________________________
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