• 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: NSComboBox -- How do I limit user typing to what is in the list
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSComboBox -- How do I limit user typing to what is in the list


  • Subject: Re: NSComboBox -- How do I limit user typing to what is in the list
  • From: Simon Wigzell <email@hidden>
  • Date: Fri, 9 Jun 2006 00:01:57 +0200

One (very) ugly solution is to use the NSTextField delegate methods:

- (void)controlTextDidChange:(NSNotification *)obj
{
NSMutableString *s = [[[comboBox stringValue] mutableCopy] autorelease];
if( s && [s length] > 0 && ![self comboBox:comboBox completedString:s] )
{
[s deleteCharactersInRange:NSMakeRange([s length] - 1, 1)];
[comboBox setStringValue:s];
}
}


Here it is assumed that your -comboBox:completedString: method returns nil if no match can be found..

This simply deletes the last character in the string if nothing matches; a better version would of course remember the last acceptable prefix and revert to that value when no completion can be found.

As mentioned this is not a pretty solution, but on the other hand you are mimicking another platform's behavior so you will have to use non- standard behavior anyway :-) And here it is definitely an NSpopUpButton which is the more natural choice, given that you are restricted to a pre-defined set of values, but unfortunately you can't use it.

Simon Wigzell

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSComboBox -- How do I limit user typing to what is in the list
      • From: John Stiles <email@hidden>
References: 
 >NSComboBox -- How do I limit user typing to what is in the list (From: Scott Mitchell <email@hidden>)
 >Re: NSComboBox -- How do I limit user typing to what is in the list (From: j o a r <email@hidden>)
 >Re: NSComboBox -- How do I limit user typing to what is in the list (From: Scott Mitchell <email@hidden>)
 >Re: NSComboBox -- How do I limit user typing to what is in the list (From: j o a r <email@hidden>)
 >Re: NSComboBox -- How do I limit user typing to what is in the list (From: Scott Mitchell <email@hidden>)

  • Prev by Date: Bindings and a dictionary
  • Next by Date: Re: NSComboBox -- How do I limit user typing to what is in the list
  • Previous by thread: Re: NSComboBox -- How do I limit user typing to what is in the list
  • Next by thread: Re: NSComboBox -- How do I limit user typing to what is in the list
  • Index(es):
    • Date
    • Thread