Cocoa bindings: How to display validation-corrected value in NSTextField
Cocoa bindings: How to display validation-corrected value in NSTextField
- Subject: Cocoa bindings: How to display validation-corrected value in NSTextField
- From: Rick Hoge <email@hidden>
- Date: Mon, 26 Apr 2004 22:26:40 -0400
I use bindings to link numeric values in NSTextFields to instance
variables in an object. This works great, but I'd like to use the
validation mechanism to check for out-of-range values when the user
enters text. The validation method, shown below, works fine in that
illegal numeric values typed in the text field are corrected on their
way to the instance variable (note that I do have 'Validate immediately
checked for the text field under the bindings tab in IB'). The
problem is that, even though the correction is effectuated, the text
field still shows the original uncorrected value. At this point the
display is not consistent with the instance variable, which is not
good.
Does anyone know how I can get the text field to respond to the
validation change?
Thanks,
Rick
// Here is my validation method (xspace is a float instance variable)
-(BOOL)validateXspace:(id*)ioValue error:(NSError**)outError {
float maxXspace = [self maxXspace];
if ([*ioValue floatValue] > maxXspace) { // X value too high?
id newVal = [NSNumber numberWithFloat:maxXspace];
*ioValue = newVal;
// I'd like to somehow correct the sender's value here...
return YES;
} else if ([*ioValue floatValue] < 0) { // Slice number too low?
id newVal = [NSNumber numberWithFloat:0.0];
*ioValue = newVal;
// Would like to correct here too...
return YES;
}
return YES;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.