Detect UISearchToken selection in UISearchTextField?

47 Views Asked by At

This should be simple perhaps I am missing it somewhere...

  • How can I detect when a user selects / highlights a UISearchToken currently presented in a UISearchTextField?

Here is a photo showing how I am trying to detect when the user selects a token: i.e. the "second" token was selected here

enter image description here


For reference, I am developing this in Swift on iOS 16+.

Upon the user hitting the "return" key, I am adding tokens to the text field:

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
    if addTokensOnReturn && !text!.isEmpty {
        insertToken(UISearchToken(icon: nil, text: text!), at: tokens.endIndex)
        text = ""
        return false
    }
    return false
}
0

There are 0 best solutions below