• 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: John Stiles <email@hidden>
  • Date: Thu, 8 Jun 2006 15:05:40 -0700

I suspect this won't work right if the user moves the cursor to the left and starts adding random characters.
It might work better if the "if" turned into a "while".
This highlights one of the biggest potential pitfalls of nonstandard behavior: everyone will implement it differently, so each application will work slightly differently, and every application will have unique, subtle bugs. That's why the OS provides a suite of (hopefully well-debugged) controls to begin with.



On Jun 8, 2006, at 3:01 PM, Simon Wigzell wrote:

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:
40blizzard.com


This email sent to email@hidden

_______________________________________________ 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
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>)
 >Re: NSComboBox -- How do I limit user typing to what is in the list (From: Simon Wigzell <email@hidden>)

  • Prev by Date: Re: NSComboBox -- How do I limit user typing to what is in the list
  • Next by Date: Re: Changing fonts without font menu?
  • 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