Re: Interface Builder & Wiring Objects
Re: Interface Builder & Wiring Objects
- Subject: Re: Interface Builder & Wiring Objects
- From: Andy Lee <email@hidden>
- Date: Mon, 17 Nov 2008 16:46:41 -0500
On Nov 17, 2008, at 2:36 PM, Greg Deward wrote:
In my example, I have the following items in my App Controller class:
Text Field (along with an IBOutlet)
Button (along with an IBOutlet)
Table View (along with an IBOutlet)
Mutable Array instance variable
The technical term for these items is "instance variable," or "ivar"
for short. Your AppController class has instance variables of type
NSTextField, NSButton, etc. which are named myTextField, myButton, or
whatever made sense to you.
You don't have ivars "along with" outlets. An outlet *is* a
particular kind of ivar. It's an object reference that is declared in
such a way that IB recognizes it and allows you to assign its value
graphically in IB. Typically the declaration has the modifier
"IBOutlet" in front of it, as in:
@interface AppController : NSObject {
IBOutlet NSTextField *myTextField;
...
}
This is just a hint to IB to say "I want you to treat this ivar as an
outlet." The IBOutlet modifier has no other effect or purpose --
indeed, it's just a macro that evaluates to nothing.
My concern is whether or not the DIRECTION in which I CTRL-drag the
objects. For example, if do I drag from the Button object to the
App Controller or do I CTRL-drag from the App Controller to the
Button?
Remember that an outlet is an object reference. You can think of an
object reference as a pointer that points TO another object. When you
Control-drag, imagine an arrowhead at the end of the line you're
dragging. You're making a connection FROM where you started the drag
TO wherever you decide to drop that arrowhead. As was explained
earlier, you're making the FROM object aware of the TO object.
In your specific example, you would drag FROM your AppController
instance to each of the objects it needs to be aware of:
"Hey app controller, I want >>this to be the text field your
myTextField outlet points to."
"Hey app controller, I want >>this to be the button your myButton
outlet points to."
Then when the nib is loaded at runtime, the app controller's ivars
will point to those respective objects.
To specify a button's target/action, you would say "Hey button
[dragging from the button], I want >>this [dragging TO the app
controller] to be your target."
Similarly:
"Hey text field, I want >>this to be your delegate."
"Hey table view, I want >>this to be your data source." (And again if
you also want to set the table view's delegate.)
--Andy
_______________________________________________
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