I have a tableViewController, MainData.swift, where I add a searchbar programmatically in it's viewDidLoad
var searchController:UISearchController!
let resultsController = SearchResultsController()
override func viewDidLoad() {
super.viewDidLoad()
searchController = UISearchController(searchResultsController: resultsController)
let searchBar = searchController.searchBar
searchBar.placeholder = "Search for a student"
searchBar.sizeToFit()
tableView.tableHeaderView = searchBar
searchController.searchResultsUpdater = resultsController
}
I then created my own class to handle the search, SearchResultsController.swift. Searching works fine but I cannot remove the header as shown here. I've tried setting the tableheaderview to nil as well as removing it from the superview but both didn't work.
func updateSearchResultsForSearchController(searchController: UISearchController) {
//code for filtering search results here
//tableView.tableHeaderView = nil
//tableView.tableHeaderView?.removeFromSuperview()
tableView.reloadData()
}
override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return nil
}
Aucun commentaire:
Enregistrer un commentaire