On 19 Jan, 2014, at 12:25 pm, Quincey Morris 
<quinceymor...@rivergatesoftware.com> wrote:

> On Jan 18, 2014, at 19:45 , Roland King <r...@rols.org> wrote:
> 
>> So perhaps the question is .. what property do I need to set on the 
>> NSTextField to get it to go back the other way? I've tried [ textField 
>> setValue:.. ] but that just throws an exception that setValue: isn't 
>> implemented on NSTextField, which it isn't, so I went back to 
>> setStringValue: But setting stringValue: changes the on-screen string, but 
>> doesn't trigger the binding to send the string back the other way. 
> 
> I think you need to setObjectValue, not setStringValue. “objectValue” is the 
> underlying property that all controls have, from which “intValue”, 
> “stringValue” etc are derived, so presumably the text field “value” binding 
> is bound to “objectValue”.
> 

'twas a good thought, and a very easy test too, but still didn't work 
unfortunately. Really does look like the binding code only fires for at the end 
of ..didFinishEditing: and not for any programatic set of any property on the 
object, at least not one I've been able to find. 

> Alternatively, don’t use ‘set<anything>’ on the text field at all, but let 
> the Browse button action method update the *data model*, and then let the 
> binding change the text field. This may seem weird, because the button action 
> method would have to apply the reverse transformer itself, but it’s actually 
> cleaner, because it doesn’t make the button behavior depend on the text field.
> 

That's what I eventually did. It's cleaner because the Browse button (and 
NSOpenPanel) produce an NSURL anyway, which I set right onto the model and that 
then updates the text field with the string value. What I was trying, and 
failing, to do before would have turned the URL into a String, set that on the 
text field and have the transformer turn it back into a URL again, which was 
contorted, but felt like it ought to have worked. 

The only bad bit about this is I had to make the model object a property of the 
view so the browse button could set the URL property on it, with bindings alone 
everything was in IB and the view object implementation had no knowledge of the 
model object at all, it just set a string path onto itself and the model was 
supposed to pick it up, except it didn't. 

But it's not horrid the way it is. Thanks for all the help. I did save a bung 
load of boilerplate code this way, there are some things I quite like moving 
from iOS to OSX. 
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to