Aha, I just read about the window's FieldEditor in the Cocoa Text
Architecture Guide. That answers most of my question. I'm still wondering
why calling textField.doubleValue during the notification changes the value
of the field. But with the field editor I can check the validity as I
wanted to.

Rob


On Fri, Aug 23, 2013 at 12:57 PM, Rob Nikander <rob.nikan...@gmail.com>wrote:

> Hi,
>
> I want to constrain an NSTextField to float values greater than zero, so I
> connected an NSNumberFormatter in Interface Builder. Now the user can enter
> invalid text (eg, "1a", "-2") but it beeps when you try to leave the field.
> That may be okay.
>
> Now I'd like to disable other parts of the UI when the field is invalid. I
> connected a delegate to the NSTextField, and implemented
> `controlTextDidChange:`, but I don't know how to check the validity from
> within that method.  I get some strange behavior when I call
> textField.doubleValue, or even textField.stringValue, from inside
> controlTextDidChange.  It causes the textfield to behave differently --
> instead of allowing invalid text and beeping later, it erases the invalid
> text as soon as you type it.
>
> So first question: why is that happening? What is getting called by
> `textField.whateverValue` to change the field?
>
> Second question: how to I ask the NSNumberFormatter about the validity of
> the field as the field changes?  I'd call its `getObjectValue...` method
> but I can seem to get the field's string value in `controlTextDidChange:`,
> without changing the behavior as described above.
>
> thanks,
> Rob
>
_______________________________________________

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