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 <cocoa-...@esoteritech.com >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 (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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to