Re: NSComboBox -- How do I limit user typing to what is in the list
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