... and I tried expressing the URL as an NSString property too, with no 
transform. Similarly calling [ textField setStringValue:<new URL to String> ] 
didn't cause the setter in the model object to be invoked. That surprised me, I 
thought binding an NSTextField to an NSString in the model object would be a 
very simple use case, set the value in the NSTextField, it would change the 
value in the model object. 

So is it possibly because I'm setting the value in code into the NSTextField 
(using setStringValue or setValue:<value> forKey:@"stringValue") instead of a 
user-interaction version of it where the text is changed via the user typing 
something in? That would seem a strange distinction. I must be missing 
something simple. 

I changed the code so that the browse button changes the URL property on the 
model object directly and the text field just updates as a result of the 
underlying URL updating in the model object, but that seems wrong, I feel I 
should be able to just change the text on the NSTextField and that would 
trigger the binding to transform the value and eventually set the URL, a 
perfect disconnect between view and model-controller. 


On 19 Jan, 2014, at 10:41 am, Roland King <r...@rols.org> wrote:

> I have a model object with a codeURL property which is readwrite and is an 
> NSURL. 
> 
> I have an NSTextField in the NSView subclass with the value bound to the 
> codeURL property with a custom transform which turns a URL into a string (and 
> deals with nil and another edge case). 
> 
> The transform is reversible, returns YES for allowsReverseTransform and has 
> an implemented reverseTransformedValue: method. 
> 
> There's a browse button on the UI which lets the user select a file and then 
> sets the stringValue: property of the NSTextField to the url.path of the file 
> selected. 
> 
> What I expected is that setting the stringValue would invoke the transformer 
> in the reverse direction and set the codeURL property to the reverse 
> transformed value, thus binding the codeURL property in both directions. 
> 
> What actually happens is nothing. The transformer reverse method isn't called 
> and the codeURL isn't changed. It works in the forward but not the reverse 
> direction. I have a checkbox similarly bound (with no transform) and that 
> works fine both ways. 
> 
> This is my first foray into bindings .. what could I be doing wrong? Do I 
> need to express a simple NSString property on the model object and bind that 
> instead and do the NSString/NSURL conversion there? 
> 
> 
> 
> _______________________________________________
> 
> 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/rols%40rols.org
> 
> This email sent to r...@rols.org


_______________________________________________

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