I am using the UISearchController and the search function works except for two things. Perhaps they are related: a) The keyboard does not show. So I cannot press the "Search" button b) In my main TableView I access the prototype cell that has the style "Subtitle". When the search is going on, the cell that shows is "Basic" style. In both cases (TableViewController and SearchViewController) I use the same cell identifier.
Any ideas? Here some of the code:
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
and the second class:
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()
}
}