Ios UISearchBar不点火

Ios UISearchBar不点火,ios,swift,uisearchbar,uisearchcontroller,uisearchbardelegate,Ios,Swift,Uisearchbar,Uisearchcontroller,Uisearchbardelegate,我将UISearchController的搜索栏放在导航栏的标题视图上。但当我点击搜索时,UISearchBar没有响应。原因可能是什么 let tvController:UITableViewController = UITableViewController() tvController.tableView.delegate = self tvController.tableView.dataSource = self self

我将UISearchController的搜索栏放在导航栏的标题视图上。但当我点击搜索时,UISearchBar没有响应。原因可能是什么

        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
这可能会有帮助

替换

self.searchController = UISearchController(searchResultsController: tvController)


您是否已将
UISearchBarDelegate
添加到UIViewController定义中?是的,我添加了UISearchBarDelegate
self.searchController = UISearchController(searchResultsController: nil)