• 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 Attributes
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Prev by Date: Newbie NSPopUpButton addItemWithTitle: problem from a menu
  • Next by Date: Why can't I introduce new variables after init stage?
  • Previous by thread: Re: NSTextField Attributes
  • Next by thread: Can't bring application frontmost
  • Index(es):
    • Date
    • Thread