Re: NSTextField Attributes
Re: NSTextField Attributes
- Subject: Re: NSTextField Attributes
- From: Anthony Arthur <email@hidden>
- Date: Fri, 24 May 2002 01:44:29 -0400
On Thursday, May 23, 2002, at 06:24 PM, Josh Aas wrote:
>
I need to have an NSTextField behave with the following attributes
>
that I
>
cannot figure out how to implement. I have tried a number of delegates
>
and
>
read through both (common) cocoa books... Sorry if this is really
>
simple!
>
>
- It must not accept pasting values into it.
For this level of control, I'm thinking you may need to subclass.
Override the keyDown: method and intercept pasting events ( you'll have
to dig around for docs on how to tell if it is a past, can't say off the
top of my head ) and send all other events to super.
>
- It must only accept four characters, and beep if the user tries to
>
enter
>
more.
>
- It must only accept alphanumeric characters (specified in
>
[NSCharacterSet
>
alphanumericCharacterSet]).
There are 2 approaches for this:
1 - You can create a formatter, subclass of NSFormatter found in
Foundation. There is a number formatter already shipped with IB, but it
won't help you with the alphas. This has to be set on the cell of the
textfield.
2 - Register your controller to receive
NSControlTextDidChangeNotification notifications. Review delegate
methods and notifications within NSControl for details..., you may find
an easier way then that.
Of these 2, I would suggest going with the formatter solution, #1. With
#2 I suspect you may get bogus notifications with a paste event, not
sure tho without testing it.
Good luck...
--Brian
>
>
Thanks!
>
-Josh Aas
>
_______________________________________________
>
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.
_______________________________________________
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.