Nirav Hathi
Nirav Hathi

Reputation: 1587

scroll to top searchbarcontroller when clicked on tableview cell

searchController move to top when I write text but when I clicking tableview cell I want same behaviour. searchController need to set top as its work on appstore app. like as shown below I tap on tableview cell so I want searchController to moves top. so what I have to write in my code.thanks

enter image description here

enter image description here

Upvotes: 2

Views: 124

Answers (1)

JsW
JsW

Reputation: 1758

Make the UITextField in the UISearchBar become the first responder() when you tap the cell.

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {


        if let searchField = searchController.searchBar.value(forKey: "searchField") as? UITextField {
            searchField.becomeFirstResponder()
        }
    }

Upvotes: 4

Related Questions