Since there is no pre-existing component for creating a combobox (or select box) as seen on webpages through Safari, can someone provide an example or pre-existing 3rd party component of creating one?
问题:
回答1:
I don't think this is hard to do.
In a view controller you have a UITextField and a UITableView. Assign the view controller to be the delegate of the both controls, plus the data source of the table.
Implement the UITextField delegate method textField:shouldChangeCharactersInRange:replacementString:
in your controller. This intercepts the changes as they are being typed in your text field. In this method, iterate through your list of possible options and store the matches in an NSMutableArray instance variable on your view controller. Then call [myTableView reloadData]
.
Have your table cells generated from the array of matches you previously stored.
It should be pretty straightforward and shouldn't take much code at all beyond a few delegate methods to get working.