IIRC, you get this behavior automatically when validating with a formatter, so applying a custom NSNumberFormatter subclass might be more canonical and less kludgey.
HTH, Keary Suska Esoteritech, Inc. "Demystifying technology for your home or business" > On May 6, 2019, at 5:33 AM, Richard Charles <rcharles...@gmail.com> wrote: > > Thank you Quincey, Sean, Gary and Alex for your comments and suggestions. > > To recap I have a NSTextField subclass bound to an array controller using a > derived value binding. The user selects one or more objects in a graphic > view. Object properties are shown in an inspector containing the text field. > > A custom derived value binding is needed because object properties are > floating point values with limited precision. Values that are close to equal > are considered equal from the user's point of view. > > When garbage is entered into a text field and the user presses the return key > an alert panel is presented as a sheet attached to the window. The user can > choose "Discard Change" or "OK”. > > Because a custom binding is used code must be added to present the error and > recover from the error. My text field subclass implements the > NSErrorRecoveryAttempting informal protocol. > > My original discard change code did not work. > > - (void)attemptRecoveryFromError:(NSError *)error > optionIndex:(NSUInteger)recoveryOptionIndex > delegate:(id)delegate > didRecoverSelector:(SEL)didRecoverSelector > contextInfo:(void *)contextInfo > { > // Discard Change > if (recoveryOptionIndex == 1) { > [self abortEditing]; // does not work > } > } > > Here is a solution that works well. > > - (void)attemptRecoveryFromError:(NSError *)error > optionIndex:(NSUInteger)recoveryOptionIndex > delegate:(id)delegate > didRecoverSelector:(SEL)didRecoverSelector > contextInfo:(void *)contextInfo > { > // Discard Change > if (recoveryOptionIndex == 1) { > // Revert display back to original value. > [self abortEditing]; > [self setObjectValue:self.cachedObjectValue]; > [self.window makeFirstResponder:self]; > } > } > > The abortEditing message is needed otherwise the binding will push the > updated cached object value to the model. > > --Richard Charles > > _______________________________________________ > > 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/cocoa-dev%40esoteritech.com > > This email sent to cocoa-...@esoteritech.com _______________________________________________ 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