Implement auto-completion on iPad

2019-09-15 03:48发布

问题:

Scenario: I have a list of medication (stored somewhere, let's say an NSArray).

There is a UITextField where a user can enter a medication to get more information about it (or whatever).

I want to suggest word completions while he is typing (but that is rather easy).

Where is the best place to show these suggestions? Since it's on the iPad i want it kinda like when you google and you get your suggestions right below the search bar. Is that possible on the iPad? A table that lays over the rest of the screen, placed below the text field? Like a pop up or something? I have never really used an iPad in my life before, therefore I don't know what the iOS way would be..

Edit: Something like this but connected to a textfield and not a button or whatever that thing is:

Edit: Or even better: Something like this but for iPad and not Android:

回答1:

In my app I used a UITableView for displaying the suggestion.

I added the tableView above my UITextField. When there is no auto complete word found, I hide the tableView.

Please check my autocomplete implemetation.



回答2:

Check out my control, MLPAutoCompleteTextField for iOS. It is a subclass of UITextField that does autocomplete.

The implementation is similar to what you are looking for in the second screenshot, and very customizable.