codename_mak codename_mak - 2 months ago 6
iOS Question

manually inserting text in uisearchbar

I need some help.

I have implemented a custom keyboard in my app on a

UIView
which stays of screen and slides up from bottom when user taps on the search bar. I am not using a keyboard target or extension.

The real question is how to insert text in
UISearchBar
when the user will press a button in my custom made keyboard.
UITextDocumentProxy
is not working here.

BTW I am developing in swift and I have added the
UISearchBar
using
UISearchBarController
programmatically.

Thanks in advance.

Answer

You can use text property of searchBar to set the text on Button action of your custom keyboard.

self.searchController.searchBar.text = "\(sender.titleLabel.text)"

OR

self.searchController.searchBar.text = "\(self.searchController.searchBar.text)\(sender.titleLabel.text)"