UISearchController 会使navgationbar变高,如果只是需要搜索框的话,或者navgationbar不想变高的话,不适用
CJResultViewController * resultVC = [[CJResultViewController alloc]init];
UISearchController * searchVC = [[UISearchController alloc]initWithSearchResultsController:resultVC];
//当输入框激活状态,整个界面会添加一个半透明的view ,默认是添加的
searchVC.obscuresBackgroundDuringPresentation = YES;
// 当输入框激活的状态,会隐藏导航条,默认状态是隐藏的
searchVC.hidesNavigationBarDuringPresentation = YES;
searchVC.searchResultsUpdater = resultVC;
searchVC.delegate = self;
self.navigationItem.searchController = searchVC;
// 滚动的时候是否隐藏搜索框,默认是隐藏的
self.navigationItem.hidesSearchBarWhenScrolling = YES;
@interface CJResultViewController : UIViewController<UISearchResultsUpdating>
@end
// 输入内容发生变化,会调用此方法
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController{
NSLog(@"%@",searchController.searchBar.text);
self.resultStr = searchController.searchBar.text;
[self.tableview reloadData];
}
网友评论