Swift UISearchController
1.遵守协议
UISearchController
2.变量声明
var sc :UISearchController!
3.viewDidLoad中实现
sc = UISearchController(searchResultsController: nil)
sc.searchResultsUpdater = self
sc.dimsBackgroundDuringPresentation = false//是否添加半透明覆盖层
self.tableView.tableHeaderView = sc.searchBar
4.实现代理方法
func updateSearchResults(for searchController: UISearchController) {
}
5. 通过 sc.isActive 属性对以下方法进行逻辑判断,重新显示tableView
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
}
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
}