Re: Neophyte Question: Connecting to nib objects
Re: Neophyte Question: Connecting to nib objects
- Subject: Re: Neophyte Question: Connecting to nib objects
- From: Kyle Sluder <email@hidden>
- Date: Mon, 19 Oct 2009 09:21:42 -0700
On Oct 19, 2009, at 8:51 AM, Phil Hystad <email@hidden> wrote:
I am new to Cocoa and I am wondering how to do something that should
be simple and obvious. Given that I have an object defined in the
nib (aka xib), for example, an object that responds to a given view,
what is the correct way for my running application (if it is in some
other state, not responding to an action) to obtain a pointer to
that object.
Gah, terminology salad!
Defined in nib: you mean instantiated here. You've defined the class
in code. It would also be helpful to know what this object does (or is
intended to do).
Respond to view: a view is a thing in a window, it can't be responded
to. It can send messages to other objects, sure, and there are a few
different categories of such methods: delegate methods (I'm gonna
resize now!), datatsource methods (What's the name of object #4?), and
target/action methods (I've been clicked! You, do the thing I was told
to make you do!) are the most common. In each case you need to wire an
object up to an outlet on the view; for target/action, you also need
to specify the selector that will be sent, so IB combines the two
properties into one "sent action" pseudo-outlet.
Maybe a second question is "Do I ever need to do this?".
That would indeed be the question, and the answer is "no." If you are
ever wanting to divine a pointer to an object from midair, you are
doing something wrong. You might just need to create an outlet and
hook up the other object to it, or your design might be flawed.
This question came about because I was experimenting with a sample
program I am using to learn Cocoa and I wanted to change the state
of the class that is defined in the nib. I did not know how to get
a pointer to that object. It seems that it is serialized (un-
archived?) when the nib is loaded.
So you have some code that loads a nib, and wants to interact with one
of the objects that lives in the nib. Typically the object that does
the nib loading is also configured as the File's Owner of the nib. So
you would define an outlet on that class and hook up your interesting
object to it in IB.
--Kyle Sluder
_______________________________________________
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