> This is the usual way to do such things. You have a controller object that
> has outlets to the views that it cares about.
and if a panel has numerous textfields, then it would be appropriate for
the subclass I create to have a large number of outlets? It seems like a
"crowded" approach, but if that's the "right" way, I want to learn it
right. I'm just not sure if that is the right way. For example, I'm
making a high scores panel for a game. I have twenty text fields, ten
names, and ten scores. Do I actually create twenty outlets in IB, and
control-click-drag twenty times to connect the outlets? Or is this a
situation where accessing the textfields through the contextView (using
tags as unique identifers) is an acceptable approach?
I already have it working using the contextView and tags, but if making a
bunch of outlets is the "cocoa" way to do it, I would rather go back and
do it right.
> Starting with Panther, you could also just use one of the reusable
> controllers and bind the value of that text field through a controller to a
> model object. In this case, you wouldn't need an outlet to the text field,
> because you wouldn't have code that cares about the text field itself at all.
Hmmm, does that give me two way access to the textfields? I need to write
to them to write the player names and high scores, but I also need to read
from one of them when the panel is done since the user types in his name
if he gets a high score. So I need both read and write access to the
textfields.
I looked up bindings on dev.apple.com and didn't get many hits btw.
> you really wanted to. But I would *strongly* encourage you to use either
> outlets or bindings instead, since that's how the framework is intended to be
> used.
Cool. Thanks.
________________________________________________________________________
Keith Wiley kwiley@cs.unm.edu http://www.unm.edu/~keithw
"Yet mark his perfect self-contentment, and hence learn his lesson,
that to be self-contented is to be vile and ignorant, and that to
aspire is better than to be blindly and impotently happy."
-- Edwin A. Abbott, Flatland
________________________________________________________________________
Chris Hanson - 14 Aug 2005 07:21 GMT
> and if a panel has numerous textfields, then it would be appropriate
> for the subclass I create to have a large number of outlets? It seems
> like a "crowded" approach, but if that's the "right" way, I want to
> learn it right.
It is the right way, but I want to be clear about something: The
controller I'm suggesting shouldn't be a subclass of NSPanel.
Generally you would only subclass NSPanel, NSWindow, etc. if you're
creating a new-kind-of-panel or new-kind-of-window (e.g. a round
window) rather than just putting-stuff-in.
> I'm just not sure if that is the right way. For example, I'm making a
> high scores panel for a game. I have twenty text fields, ten names,
> and ten scores. Do I actually create twenty outlets in IB, and
> control-click-drag twenty times to connect the outlets? Or is this a
> situation where accessing the textfields through the contextView (using
> tags as unique identifers) is an acceptable approach?
For something like that, it might be more worthwhile to use an NSForm
or NSMatrix. These let you index into a collection of cells (either by
index, or by row/column), which may fit what you're trying to do more
closely.
> Hmmm, does that give me two way access to the textfields? I need to
> write to them to write the player names and high scores, but I also
> need to read from one of them when the panel is done since the user
> types in his name if he gets a high score. So I need both read and
> write access to the textfields.
When you change the value of a bound property in a model object,
anything bound to that property will be updated to reflect the new
value.
When you manipulate a view that is bound to a property of a model
object, the property will be changed accordingly. (And anything else
bound to that property will be updated to reflect the new value.)
> I looked up bindings on dev.apple.com and didn't get many hits btw.
I just searched developer.apple.com for "cocoa bindings" (no quotes)
using the search field on the main page. I got back 459 hits, the
first five of which are:
Cocoa Bindings Programming Topic: What Are Cocoa Bindings?
Developing Cocoa Applications Using Bindings: A Tutorial
Cocoa Bindings Programming Topic: Troubleshooting Cocoa Bindings
Cocoa Bindings Programming Topics: Introduction to Cocoa Bindings
Cocoa Performance Guidelines: Cocoa Bindings Tips
There should be a lot of information on bindings available from both
developer.apple.com and in the ADC Reference Library accessible via
Xcode.
I'll grant that the first few hits if you search for just "bindings"
are WebObjects-related.
-- Chris
Patrick Machielse - 14 Aug 2005 10:54 GMT
> > But I would *strongly* encourage you to use either outlets or bindings
> > instead, since that's how the framework is intended to be used.
>
> Cool. Thanks.
All methods of getting a reference to the text field are equally valid.
They are _all_ in the framework, and they are in there to be used. Use
the method that suits your needs best. Depending on the situation that
may be enumerating an NSMatrix, using Bindings, or indeed -viewWithTag:
patrick
Keith Wiley - 14 Aug 2005 17:02 GMT
> All methods of getting a reference to the text field are equally valid.
> They are _all_ in the framework, and they are in there to be used. Use
> the method that suits your needs best. Depending on the situation that
> may be enumerating an NSMatrix, using Bindings, or indeed -viewWithTag:
:-) Appreciate the support.
Cheers!
________________________________________________________________________
Keith Wiley kwiley@cs.unm.edu http://www.unm.edu/~keithw
"Yet mark his perfect self-contentment, and hence learn his lesson,
that to be self-contented is to be vile and ignorant, and that to
aspire is better than to be blindly and impotently happy."
-- Edwin A. Abbott, Flatland
________________________________________________________________________