• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Binding button.enabled to "NSTextField is not empty"
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Binding button.enabled to "NSTextField is not empty"


  • Subject: Re: Binding button.enabled to "NSTextField is not empty"
  • From: Alex Clarke <email@hidden>
  • Date: Wed, 27 Apr 2005 18:15:09 +1000
  • Organization: PowerMax Computers

From: Alex Clarke <email@hidden>
Date: Wed, 27 Apr 2005 17:20:46 +1000
To: Andrew White <email@hidden>
Subject: Re: Binding button.enabled to "NSTextField is not empty"

Hi Andrew,

> My understanding of the basic model (based on Ken's code):

 I have an NSObjectController.  This models my "system".  I add a
 "myText" (or "myString" in Alex' code) property to this controller to
 hold the text that both the field and the button will operate upon.

No. I haven't seen Ken's example, but I think perhaps you are confusing my traditional App Controller with the newfangled NSController. Sorry I didn't post my notes with my project which would have avoided the confusion.

For anyone who's interested, I have posted a link to the example I sent to Andrew here:

Have a look at http://www.cocoalab.com/examples/minimalbindings/minimalbindings.zip

I have also posted an explanatory rtf file in the same directory. Please read this Andrew to get a clearer idea of what is going on in my project. I am working up a tutorial here (yes! another bindings tutorial) so any feedback is most welcome.

I'm not any kind of an expert on these matters, I just know what works for me. The example is my attempt to make the minimal amount of code/wiring to get a simple binding to work.

> I associate the value of the text field with the value of
 'selection.myText'.  Changes to one will be reflected in the other.

 I associate the 'enabled' state of the button with the value of
 "selection.myText" transformed through a NSIsNotNil boolean test.
 When selection.myText changes, the value of this transformation will
 also change.


 Now the inevitable questions:

 (1) Why do you bind to 'selection' rather than some other key?

Because Selection is the selected object in the array, and a text view can only show one of the array's members at once. A tableView would bind to arrangedObjects.

[...snip...] I'll let the more experienced/knowledgeable answer your other questions.

> To Alex specifically:

 (5) Why use a controller object and a NSArrayController rather than
 an NSObjectController?

Because it works! I have not yet used NSObjectController in a project, I find NSArrayController to be appropriate for most cases. I mean, it tracks a collection of objects, which is what I usually want to do. It tracks the selected object. What's not to like?

> General again:

 (6) If I want to snarf the value of the text field (as part of the
 action invoked when the button is pressed), do I connect my outlet to
 the text field or to the NSObjectController?  What is the functional
 difference?  Is one or other preferred?

As mmalc says, don't think of binding the value in the text field. This is not the way to think about it. you have a value in the Model. The model is kinda like a database. The view is just a bunch of fancy stuff to display it to the user. That same data could very well be displayed in a table view.

Rather, think about how to access your value in the Model. Bindings ensures that however the data is displayed, the View dynamically reflects the Model. That's all.

A

----       -----      ----       -----      ----       -----      ----       -----      ----       -----

Alex Clarke
email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Binding button.enabled to "NSTextField is not empty" (From: Andrew White <email@hidden>)

  • Prev by Date: fun with NSTextView (almost-newbie)
  • Next by Date: app with MDquery won´t launch in 10.3
  • Previous by thread: Re: Binding button.enabled to "NSTextField is not empty"
  • Next by thread: determining front most document?
  • Index(es):
    • Date
    • Thread