Re: How to use a button to update an application with a text field value
Re: How to use a button to update an application with a text field value
- Subject: Re: How to use a button to update an application with a text field value
- From: Tron Thomas <email@hidden>
- Date: Wed, 06 Aug 2008 19:55:45 -0700
I attempted to try out what you were suggesting to see how well I
understood it. I got a compiler warning that said my controller class
may not respond to -selection.
Also, in the case where a controller might have selector that take
multiple arguments, I'm not sure how I could provide the arguments.
Suppose the selector wanted access to the text field, I'm not sure how I
could specify that object as an argument in the button's binding.
Ron Lue-Sang wrote:
Hmmm...
In no particular order (sorry)
- Even if the user hasn't typed into the textfield, the property that
the textfield is bound /to/ will have a value that matches. This means
that if I have a textField bound to MyArrayController.selection.name
<http://MyArrayController.selection.name>. When I want that name, I
just do [MyArrayController valueForKeyPath:@"selection.name
<http://selection.name>"]. That will match the value that is in the
textField. The textField is reflecting that value.
- You can use the target/argument bindings for this case if you want.
This has the advantage that your "action" method won't have to do the
commitEditing step itself. Also you won't have to expose the method as
an IBAction or anything. The target binding invokes the commitEditing
(or commitEditing with delegate) method on the the bound-to object,
which in this case is your NSController. NSControllers implement the
whole set of NSEditor and NSEditorRegistration methods. That's why
this all works. If you bind to an object that doesn't implement the
full set of methods, you have to do more work.
- To establish a target binding, the "to" object is just the
controller (in this case). The keypath can be self. The selector is an
option in the binding editor in IB. If you method is
- (void)doWork;
type "doWork" (without the quotes) into the selector field in the
binding editor.
If your method takes arguments, you'll have to change the selector.
Instead of "doWork", you'd have "doWorkWithObject:" - note the colon.
Or "doWorkWithObject:usingNeighborsHedgeClippers:returnWhenDone:"
For each argument you have, you'll need to bind the argument binding
to provideā¦ an argument.
If you've followed what I've outlined here, you can just implement
doWork like this
- (void)doWork {
NSString *name = [[self selection] valueForKeyPath:@"name"]; //
note, won't matter whether user's typed yet
NSLog(@"here's the name! %@", name);
}
Make sense?
_______________________________________________
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