• 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: A question about binding and use
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A question about binding and use


  • Subject: Re: A question about binding and use
  • From: mmalcolm crawford <email@hidden>
  • Date: Mon, 7 Mar 2005 14:53:44 -0800


On Mar 7, 2005, at 12:39 PM, Scott Ellsworth wrote:

FROM : beauvais
DATE : Mon Mar 07 15:41:44 2005
[...]
Bindings are not a magic bullet - they exist to replace the glue code in your app, and to provide a very fast notification service. When your app is doing something other than those two tasks, bindings do not help.


Agreed, but...


How would you add customization of an action when you are trying to take advantage of the Cocoa bindings.
The action would be just like it would have been prior to bindings, save that it does not change the values of screen objects, it changes the values of objects that the ui is observing.

Action bindings represent an interesting case -- it is possible to invoke much more interesting methods using bindings than the simple action:sender method. In particular, for example, you can pass as arguments, say, the selection of an array controller, or another value to which you can bind. Thus...


For example: Assume your app is just a user visible text label, a text field, and button. When the button is pressed, the value is copied from the text field to the string,
Prior to bindings, you would have a the string and the text field as IBOutlets. Your IBAction procedure would call setText on the string, using the result of getText on the entry field.
Your new code is very similar, save that you bind the contents of the text field to some NSString *, perhaps called fieldValue, in your document and the string to an NSString * in your document, perhaps called labelValue. Your action procedure merely sets the labelValue from fieldValue. You can write a setter method, call setValue:forKey:, or edit the underlying field directly after bracketing it with calls to will/didChangeValueforKey:
In other words, assuming fieldValue and labelValue accessors, and appropriate bindings hooking up the field/label GUI elements to the underlying objects in MyDocument, the method is just:
- (IBAction)doButton:(id)sender
{
[self setLabelValue:[self fieldValue]];
}
The bindings mechanism will handle the needed notifications.


... it may well be the case that you don't need a doButton: action method. You could set the selector of an action binding to setLabelValue:, and the argument to be the key path to the field value. (I'm not quite sure I see the rationale behind this particular example, but...)

mmalc


_______________________________________________ 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: A question about binding and use (From: Scott Ellsworth <email@hidden>)

  • Prev by Date: Re: [Newbie]: Proper window activation
  • Next by Date: Document Icon for Cocoa Application
  • Previous by thread: Re: A question about binding and use
  • Next by thread: Weird image size
  • Index(es):
    • Date
    • Thread