Ios 使用不带故事板的UISearchController
我对iOS比较陌生(100小时左右),我正在尝试实现一个没有故事板的UISearchController。有可能通过编程实现吗?您必须通过编程实现Ios 使用不带故事板的UISearchController,ios,uitableview,uisearchcontroller,Ios,Uitableview,Uisearchcontroller,我对iOS比较陌生(100小时左右),我正在尝试实现一个没有故事板的UISearchController。有可能通过编程实现吗?您必须通过编程实现UISearchController,因为苹果还没有提供使用故事板进行设置的功能 以下是在视图控制器中实现UISearchController的步骤 符合UISearchResultsUpdate协议 创建一个变量以引用UISearchController var searchController: UISearchController! 在vi
UISearchController
,因为苹果还没有提供使用故事板进行设置的功能
以下是在视图控制器中实现UISearchController
的步骤
- 符合
协议UISearchResultsUpdate
- 创建一个变量以引用
UISearchController
var searchController: UISearchController!
- 在
viewdiload(:)
- 实现方法
,当搜索栏成为第一响应者或当用户更改搜索栏内的文本时调用该方法updateSearchResultsForSearchController(:)
func updateSearchResultsForSearchController(searchController: UISearchController) { // No need to update anything if we're being dismissed. if !searchController.active { return } // you can access the text in the search bar as below filterString = searchController.searchBar.text // write some code to filter the data provided to your tableview }
func updateSearchResultsForSearchController(searchController: UISearchController) {
// No need to update anything if we're being dismissed.
if !searchController.active {
return
}
// you can access the text in the search bar as below
filterString = searchController.searchBar.text
// write some code to filter the data provided to your tableview
}