我想在我的tableView
上实现一个UISearchBar
。
我的代码(在viewDidLoad中):
self.searchController = UISearchController(searchResultsController: nil)
self.searchController.searchResultsUpdater = self
self.searchController.delegate = self
self.searchController.searchBar.delegate = self
self.searchController.searchBar.autocapitalizationType = .None
self.searchController.searchBar.autocorrectionType = .No
self.searchController.hidesNavigationBarDuringPresentation = false
self.searchController.dimsBackgroundDuringPresentation = false
self.tableView.tableHeaderView = self.searchController.searchBar
当我点击搜索栏时,这个搜索栏会移动到顶部,就像它想要隐藏导航栏一样。如下图所示:
![When the searchbar is waiting](https://istack.dev59.com/LDseZ.webp)
![When I click in the searchbar](https://istack.dev59.com/MEBAy.webp)
self.edgesForExtendedLayout = .None
和self.searchController.edgesForExtendedLayout = .None
。结果是一样的。 - Robin