UISearchController – 键盘不显示

我正在使用UISearchController和searchfunction,除了两件事。 也许他们是相关的:a)键盘不显示。 所以我不能按“search”buttonb)在我的主TableView我访问样式单元格的样式“副标题”。 当进行search时,显示的单元格是“基本”样式。 在这两种情况下(TableViewController和SearchViewController)我使用相同的单元格标识符。

有任何想法吗? 这里的一些代码:

class OverviewTableViewController: UITableViewController { override func viewDidLoad() { super.viewDidLoad() let resultsController = SearchResultsController() resultsController.birds = birds searchController = UISearchController(searchResultsController: resultsController) //searchController.dimsBackgroundDuringPresentation = true let searchBar = searchController.searchBar searchBar.scopeButtonTitles = ["One", "Two"] searchBar.placeholder = "Search" searchBar.sizeToFit() tableView.tableHeaderView = searchBar searchController.searchResultsUpdater = resultsController 

和第二类:

 class SearchResultsController: UITableViewController, UISearchResultsUpdating { var items: [Item] = [] var filtered: [Item] = [] override func viewDidLoad() { super.viewDidLoad() tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell") } // MARK: - UISearchResultsUpdating Conformance func updateSearchResultsForSearchController(searchController: UISearchController) { //searchController.hidesNavigationBarDuringPresentation = true let searchString = searchController.searchBar.text let buttonIndex = searchController.searchBar.selectedScopeButtonIndex filtered.removeAll(keepCapacity: true) if !searchString.isEmpty { for item in items { ... } } self.tableView.reloadData() } } 

我有同样的问题,基本上,如果你的父类有一个UISearchController以及你的子类,你设置

self.definesPresentationController = YES

在你的父类中,你的子类的search控制器将不会显示键盘。 花了我一段时间弄清楚,但这是发生了什么事情。

解决它的方法是设置self.definesPresentationController = NO当您的父类将要推入子类,并在您的父类的viewWillAppear中设置self.definesPresentationController = YES

希望这可以帮助那里的人。

在我的主TableView我访问具有样式“Subtitle”的原型单元格。 当进行search时,显示的单元格是“基本”样式

确保SearchResultsController中的单元格也是“Subtitle”风格的。

除了做其他用户的build议,我也做了以下,它的工作:

searchController.definesPresentationContext = true