On May 1, 2012, at 16:23 , Ben Kennedy wrote:

> I confess to have mis-described my situation somewhat: while most columns 
> were bound, several instead used the classical NSTableViewDataSource style, 
> including the one for which I'm having the validation trouble.  Sure enough, 
> when I connect a binding for that column, the formatter-imposed validation 
> now works -- regardless of whether "validates immediately" is in force or 
> not, contrary to your suggestion.  (I was certain that I had tested that 
> already, but apparently I didn't.)
> 
> However, the reasons I'm serving data for this column programatically are
> 
> a) to offset the displayed value according to a document-level property (when 
> the data set is in a "read-only" mode), and
> 
> b) to be able to calculate and apply a related change to other columns when 
> the current value is modified.
> 
> Before I started using NSArrayController or bindings, validation used to 
> work.  There must be something else I have overlooked here.  Why is 
> validation failing for the non-binding (NSTableViewDataSource-backed) columns?
> 
> Additionally: for a bound column, my understanding is that 
> validate<Key>:error: should be called against the object to check validity 
> (at least in the absence of an attached formatter).  However, it doesn't.  Is 
> there a prerequisite I am failing to satisfy?

I'm not aware that KVC-style validation ever happens automatically *except* for 
bindings that have have "Validates immediately" checked. This idea is supported 
by the KVC documentation:

        
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/KeyValueCoding/Articles/Validation.html#//apple_ref/doc/uid/20002173-CJBDBHCB

AFAIK, the validation performed by a number formatter is limited to its own 
internal understanding (modified by the properties you set) of what a valid 
number looks like. I don't see how it could know what validate<Key>: method to 
call.

OTOH, if your bindings-based validation isn't working at all, then there's also 
some other factor at play here. It's worth triple-checking that you haven't 
misspelled a property name or a method name, causing the validation method to 
no longer match the property.

The other factor with validation methods is that the presence of a formatter 
changes what class of object the validation receives. Without any formatter, it 
gets a NSString (from a text field UI element). With a number formatter, it 
gets a NSNumber. Depending on how the validation method is coded, it might be 
doing the wrong thing if it gets an object of the "wrong" class.

_______________________________________________

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