0301——SearchController
?創(chuàng)建顯示的頁(yè)面
? ? ? ?SearchViewController * searchVC = [[SearchViewController alloc]init];
告訴搜索控制器將結(jié)果顯示在創(chuàng)建的頁(yè)面上
? ? ? ?self.searchController = [[UISearchController alloc]initWithSearchResultsController:searchVC];
? ?由誰(shuí)來(lái)監(jiān)聽(tīng)搜索內(nèi)容發(fā)生的事件
? ? ? ?self.searchController.searchResultsUpdater = self;
? ?在tableview上方顯示searchbar
? ? ? ?self.MyTableView.tableHeaderView = _searchController.searchBar;
? ?設(shè)置提供顯示新頁(yè)面
? ? ? ?self.searchController.definesPresentationContext= YES;
? ?
?
<UISearchResultsUpdating>
代理方法
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController{? ?
? ?設(shè)置查找條件
? ? NSPredicate * predicate = [NSPredicate predicateWithFormat:@"SELF contains[cd] %@",searchController.searchBar.text];
? ?過(guò)濾出結(jié)果
? ? NSArray * results = [_dataSourceArray filteredArrayUsingPredicate:predicate];
? ?找到應(yīng)顯示的結(jié)果位置searchResultsController
? ? SearchViewController *sResultCtrl = (SearchViewController *)_searchController.searchResultsController;
? ?設(shè)置數(shù)據(jù)源
? ? sResultCtrl.dataSourceArray = results;
}
?
?
結(jié)果類?SearchViewController?中
- (void)setDataSourceArray:(NSArray *)dataSourceArray{
? ? _dataSourceArray = dataSourceArray;
? ? 刷新列表
? ? [self.myTableView reloadData];
}
轉(zhuǎn)載于:https://www.cnblogs.com/damonWq/p/5229675.html
總結(jié)
以上是生活随笔為你收集整理的0301——SearchController的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: bootstrap基础学习十篇
- 下一篇: sed替换变量