Re: NSTextField Attributes
Re: NSTextField Attributes
- Subject: Re: NSTextField Attributes
- From: Josh Aas <email@hidden>
- Date: Fri, 24 May 2002 23:28:43 -0500
I don't actually need alphanumeric only entries any more. But if I did, I'd
take the recommendation of using a custom NSFormatter. The formatter class
is too complex for me to learn right now, as I don't have much time. The
solution I posted is exactly what I stuck with. Sorry for posting what seems
to end up being a rather pointless newbie one. Thanks for the
recommendations!
-Josh
>
Ok, not sure what your question is here, but it appears you are
>
correctly using the notification system. Since it appears you need to
>
control the enabledness of a button based on the length of entered text,
>
then this is probably the best way to do that. With the alphnumeric
>
filtering I am still convinced your best bet is to use a subclass of
>
NSFormatter ( did you see the message from Doug Davidson? ). Also,
>
preventing a past event will probably require a subclass of NSTextField.
>
>
Meanwhile, you appear to be making progress.
>
>
-b
>
>
On Friday, May 24, 2002, at 05:54 PM, Josh Aas wrote:
>
>
> Alright - I haven't solved my problem with only accepting alphanumeric
>
> characters (I'm close though), but here is the solution to the other
>
> two...
>
> Using this delegate prevents bad copy-paste and won't allow the user to
>
> enter more than four characters...
>
>
>
> - (void)controlTextDidChange:(NSNotification*)aNotification {
>
> if ([[extensionTextField stringValue] length] > 4) {
>
> NSBeep();
>
> [extensionTextField setObjectValue:LastExtensionValue];
>
> }
>
> if ([[extensionTextField stringValue] length] > 0) {
>
> [addExtensionButton setEnabled:YES];
>
> }
>
> else {
>
> [addExtensionButton setEnabled:NO];
>
> }
>
> LastExtensionValue = [extensionTextField stringValue];
>
> }
>
>
>
>> 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.
>
> _______________________________________________
>
> 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.