UITextField autocomplete
Is it possible to autocomplete a UITextField bases on what is being entered? The reason why I need this is because I have a predefined set of words that the user needs to choose and the list is about 1000 item long. I want to display in UITableView and let the user chose but having 1k items in tabl开发者_如何学运维e list isn't I think a good idea. Thanks
You can do it by not showing all the 1k items in table view but you can populate your table view as the user starts typing letters in text field. For this you have to put all the items in some data structure or database from where you can use some sorting or query to get the items related to what is user entered. For example if user starts typing letter from 'a' then get the items which have letter a and populate your table with them. One way of doing this is put all in database and in UITextField
delegate
- (void)textFieldDidBeginEditing:(UITextField *)textField
start a NSTimer
object which will call a function for every one second and that function will give you selected data from database, populate your table with that data.
Also you have to stop that timer in UITextField
delegate -
- (BOOL)textFieldShouldReturn:(UITextField *)textField
or
-(void) textFieldDidEndEditing:(UITextField *)textField
You'll need to leverage TextFieldTextDidChange
, as mentioned here: How can I get a textDidChange (like for a UISearchBar) method for a UITextField? but just how you present the available set, I'm not so sure...you could keep the table empty until X characters are entered and then search for matches to populate your (now smaller) table with
精彩评论