• 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: NSTextField input validation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTextField input validation


  • Subject: Re: NSTextField input validation
  • From: Keary Suska <email@hidden>
  • Date: Tue, 13 Jan 2009 11:34:27 -0700


On Jan 13, 2009, at 10:32 AM, Adam Venturella wrote:

It is my understanding that, NSTextFieldCell gets the windows field editor
when the user goes to edit the cell's contents. How I understood the docs
was that I need to override the cell's: setUpFieldEditorAttributes: as that
is the point at which the cell is getting the windows field editor. Once I
have that I can adjust it accordingly. Or I can override the NSWindows's
windowWillReturnFieldEditor:toObject: to customize it there.
Is there a location, in IB or otherwise that lets me configure the Field
Editor outside of the above methods?

Well, the cell is asked to customize or replace the field editor, but the cell itself never "gets" the editor. The only purpose of the cell is to draw the UI on behalf of the NSTextField. Even the NSTextField doesn't know its editor--only the window does. The important thing is that the text editing system assigns the NSTextField (not the cell) as the delegate automatically. Changing this could have unintended consequences--especially difficult to track bugs. So, I wouldn't interfere with that.


It is probably better to subclass NSTextField instead, and implement the desired delegate method. I don't think the method you want is implemented, but you should check anyway, and if it is, you may want to call super's implementation.

On a different note, there may be a number of pitfalls. For instance, if you wish to allow any truly numeric value, vs. just digits. There may be also be some localization issues. Just FYI.

HTH,

On Tue, Jan 13, 2009 at 8:23 AM, Keary Suska <email@hidden >wrote:


On Jan 12, 2009, at 5:22 PM, Adam Venturella wrote:

So there we have it. Again this does do exactly what I want it to do, if
the user tries to enter a letter or anything not a number, I get an
NSBeep(); It works if the operation is a paste operation or initiated by a
keystroke.


My main question, am I doing the right thing by casting the NSText into a
NSTextView, and is the NumberFormatter the best way to go in order to test
for a valid number or should I go the NSScanner route?



Subclassing NSTextFieldCell seems a bit unnecessary--why not just set the
NSTextField delegate to one of your controllers? The whole
-setUpFieldEditorAttributes seems a bit kludgey to me (and possibly prone to
errors).


Also, I would use an NSCharacterSet (-characterIsMember:) instead of
NSFormatter or NSSCanner. Much more lightweight.


Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

_______________________________________________

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: 
 >NSTextField input validation (From: "Adam Venturella" <email@hidden>)
 >Re: NSTextField input validation (From: Keary Suska <email@hidden>)
 >Re: NSTextField input validation (From: "Adam Venturella" <email@hidden>)

  • Prev by Date: Re: Using UIImageView for animations
  • Next by Date: Re: runModalForWindow, best solution to modal session
  • Previous by thread: Re: NSTextField input validation
  • Next by thread: [JOB] iPhone Developer, NYC - 80-110k
  • Index(es):
    • Date
    • Thread