1.searchController没有界面控件可供拖拽
只能手写代码
#pragma mark ----搜索
-(void)search{
//创建UISearchController
_searchController = [[UISearchController alloc]initWithSearchResultsController:nil];
//设置代理
_searchController.delegate = self;
_searchController.searchResultsUpdater= self;
self.searchController.dimsBackgroundDuringPresentation=NO;//背景变暗色
self.searchController.obscuresBackgroundDuringPresentation=NO;//背景模糊
//自定义中文取消
_searchController.searchBar.showsCancelButton = YES;
UIButton *canceLBtn = [_searchController.searchBar valueForKey:@"cancelButton"];
[canceLBtn setTitle:@"取消" forState:UIControlStateNormal];
[canceLBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
_searchController.searchBar.placeholder = @"输入";
//背景
// _searchController.searchBar.barTintColor = kWhiteColor ;
//边框
// _searchController.searchBar.searchBarStyle = UISearchBarStyleProminent;
// 添加 searchbar 到 headerview
self.tableView.tableHeaderView = _searchController.searchBar;
}
https://www.cnblogs.com/jukaiit/p/5063942.html
2城市选择器
https://www.jianshu.com/p/e1d7a1030cb6
这个东西缺城市 ,看上面的链接,可以手动添加,城市id不重复就行了。


//1.把searchController加到view上;
@property (nonatomic, strong) UISearchController *searchController;
UIView * headView=[[UIView alloc]initWithFrame:CGRectMake(0, 0,300, 88)];
[headView addSubview: self.searchController.searchBar];
3.searchBar导航条高度变化
push进一个search的页面再出来有缝隙


//原因
self.navigationItem.titleView = self.searchController.searchBar;
//只需要加上下面的代码就ok了
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.searchController.active = NO;
self.navigationItem.titleView = nil;
}
网友评论