Re: Combo box data validation question
Re: Combo box data validation question
- Subject: Re: Combo box data validation question
- From: Brian Webster <email@hidden>
- Date: Fri, 21 Jun 2002 13:46:05 -0500
On Friday, June 21, 2002, at 11:41 AM, cocoa-dev-
email@hidden wrote:
What I'd like to be able to do is take the value the user types
in and check and see if it's the right type--did the user
actually type in a date or did he type in a number. My first
thought was NSFormatter, but that doesn't seem appropriate.
A formatter is exactly what you want. Its job is to translate
back and forth between an object value that is stored in a
control and the string representation of that value that is
displayed to/entered by the user. For instance, if you set a
control's formatter to be an instance of NSDateFormatter, you
can then set the object value of the control to be an NSDate.
The formatter will translate the NSDate into an NSString to be
displayed in the control and will also translate the string
typed in by the user into an NSDate for storage. If the user
types in something invalid, your control's delegate will get a
control:didFailToFormatString:errorDescription: message which
you can handle.
However, -objectValue: is always returning a string; I'm
guessing this is because a combo box is a subclass of a text
field, and anything the user types can be a string.
When there is no formatter attached to a control, there is no
conversion back and forth of the string to a different type of
object, so its objectValue will simply be the string it displays.
--
Brian Webster
email@hidden
http://homepage.mac.com/bwebster
_______________________________________________
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.