• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to observe validity of NSTextField+NSNumberFormatter?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to observe validity of NSTextField+NSNumberFormatter?


  • Subject: Re: How to observe validity of NSTextField+NSNumberFormatter?
  • From: Rob Nikander <email@hidden>
  • Date: Fri, 23 Aug 2013 14:51:12 -0400

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 <email@hidden>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 (email@hidden)

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:

This email sent to email@hidden


References: 
 >How to observe validity of NSTextField+NSNumberFormatter? (From: Rob Nikander <email@hidden>)

  • Prev by Date: Re: Protocols and the +initialize class method
  • Next by Date: Re: Protocols and the +initialize class method
  • Previous by thread: How to observe validity of NSTextField+NSNumberFormatter?
  • Next by thread: Re: How to observe validity of NSTextField+NSNumberFormatter?
  • Index(es):
    • Date
    • Thread