0
votes

I put my UISearchController's search bar on navigation bar's titleView. But when I tap to search, UISearchBar does not respond. What can be the cause ?

        let tvController:UITableViewController = UITableViewController()
        tvController.tableView.delegate = self
        tvController.tableView.dataSource = self
        self.searchController = UISearchController(searchResultsController: tvController)
        self.searchController?.searchResultsUpdater = self
        self.searchController!.searchBar.placeholder = "Search for places"
        self.searchController!.hidesNavigationBarDuringPresentation = false
        self.searchController!.dimsBackgroundDuringPresentation = false;
        self.searchController!.searchBar.searchBarStyle = UISearchBarStyle.Prominent
        self.searchController!.delegate = self
        self.searchController!.searchBar.delegate = self
        self.definesPresentationContext = true
        self.searchController!.searchBar.sizeToFit()
        self.navigationItem.titleView = self.searchController!.searchBar
1
Have you add UISearchBarDelegate to your UIViewController Definition?blacksheep_2011
Yes I added UISearchBarDelegateuahakan

1 Answers

0
votes

This might help

Replace

self.searchController = UISearchController(searchResultsController: tvController)

With

self.searchController = UISearchController(searchResultsController: nil)