AlexCon
AlexCon

Reputation: 1217

Multi-Tag Auto Complete Textfield in Apple iOS development with Swift

So far I could accomplish Auto Complete feature on a Textfield UI in Xcode 6 for my iOS app, but my challenge is to make it take multiple tags and then show suggestion for each one. For example:

Enter "Ja" and it shows "Java" in the list, I choose that, type "," and it make it a tag, then I start typing "PH" and it shows "PHP", and I choose that and place another "," and so on. Just like the Jquery Auto-complete for multiple tags. Is there a way to accomplish this in iOS ?

Link to Jquery AutoComplete Plugin

Upvotes: 6

Views: 1570

Answers (1)

Husam
Husam

Reputation: 8568

Use WSTagField library by whitesmith

Since you have completed the autocompletion logic. You just need to show the results in a UITableView. Then use WSTagField as shown below to show/hide suggestions table view.

let tagsField = WSTagsField()

// Events
tagsField.onDidAddTag = { field, tag in
    //Remove suggestions tableview from the view
    print("DidAddTag", tag.text)
}

tagsField.onDidChangeText = { _, text in
    //Add suggestions table to the view
}

tagsField.onDidChangeHeightTo = { _, height in
    //Update suggestions table frame to prevent tag field covering
}

tagsField.onValidateTag = { tag, tags in
    // validate tag here to match your tags list
}

enter image description here

Upvotes: 2

Related Questions