Re: Using ComboBox as a search field and selector - newbie solicits advice
Re: Using ComboBox as a search field and selector - newbie solicits advice
- Subject: Re: Using ComboBox as a search field and selector - newbie solicits advice
- From: Scott Ribe <email@hidden>
- Date: Sat, 17 Dec 2005 17:30:14 -0700
- Thread-topic: Using ComboBox as a search field and selector - newbie solicits advice
>
Am I on the right track? Any words
>
of wisdom?
ComboBox is not really designed to support this kind of use, so you'll
probably have to work around a couple of quirks, but I think you can do
roughly what you want. A few notes:
Your controller becomes both the delegate and the data source for the combo
box.
The control:textShouldEndEditing: message will be called however the user
tries to leave the combo, enter, tab, clicking elsewhere. This would be a
good place to do the lookup, just using [combo stringValue], rather than
trying to trap the return key.
The controlTextDidChange: message will be called whenever the text in the
combo box is edited. This is a good place to note that a new lookup needs to
be performed when the combo is about to lose focus.
Also, one can implement the comboBoxWillPopUp notice and perform the lookup
there, calling noteNumberOfItemsChanged and reloadData from within the
notice. Thing is, that causes the menu to *not* pop, so then you have to use
an undocumented API to go ahead and get it to pop down. There is an
undocumented (void) popUp: (id) sender message that comboBox will take. If
you need to use it, you have to declare a popUp message somewhere so the
compiler knows about it and you can send it to your controls. You send it to
the cell, not the actual combo, so: [[combo cell] popUp: nil]. And of course
if you do this, you should file a radar enhancement request explaining why
you need the functionality, so maybe it will become part of the public
supported interface ;-)
I think the menu may pop if the user hits the down arrow. (Am I remembering
that right???) And if so, it works fine with the above techniques, because
the willpop notice will be called...
Once you think you have it working, take some time to experiment with
editing, copying, pasting, tabbing, shift-tabbing, clicking, getting part
way through using it and then using some other control, making a choice and
doing some other things then trying to use it again, making a choice and
immediately shift-tabbing back in to try again. There can be subtle little
issues around keeping things straight so that it doesn't get into some odd
state...
Ultimately, it would be a better design to use a custom subclass of combo
than to have all this code in the controller, with all the switch statements
to do the different things for the different combos.
--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 665-7007 voice
_______________________________________________
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