美文网首页
UISearchController

UISearchController

作者: 流年易逝_李 | 来源:发表于2018-03-29 01:04 被阅读12次

// 设置搜索视图

let controller =UISearchController(searchResultsController:nil)

controller.searchBar.delegate=self  //两个样例使用不同的代理

controller.hidesNavigationBarDuringPresentation = false

controller.dimsBackgroundDuringPresentation = false

controller.searchBar.searchBarStyle= .minimal

controller.searchBar.sizeToFit()

self.tableView.tableHeaderView= controller.searchBar

// tableView 代理方法设置列表cell时,根据self.countrySearchController.isActive决定是源数据,还是搜索结果

// 搜索bar点击事件的代理方法,修改搜索结果

//点击搜索按钮

func searchBarSearchButtonClicked(_searchBar:UISearchBar) {

        self.searchArray=self.schoolArray.filter{ (school) ->Boolin

            return school.contains(searchBar.text!)

        }

}

相关文章

网友评论

      本文标题:UISearchController

      本文链接:https://www.haomeiwen.com/subject/ciupcftx.html