//tableview
self.specialAttentionTableView = [[BATableView alloc] initWithFrame:CGRectMake(0, 64 + searchBarH, self.view.frame.size.width, self.view.frame.size.height - 50)];
self.automaticallyAdjustsScrollViewInsets = NO;
self.specialAttentionTableView.delegate = self;
[self.view addSubview:self.specialAttentionTableView];
//searchBar
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, searchBarH)];
_searchBar.placeholder = @"Search";
_searchBar.delegate = self;
[self.view addSubview:_searchBar];
//searchDisplayController
_searchDisplayController = [[UISearchDisplayController alloc]initWithSearchBar:_searchBar contentsController:self];
_searchDisplayController.searchResultsDataSource = self;
_searchDisplayController.searchResultsDelegate = self;
如果我将SearchBar
添加到self.view
,则SearchBar
不会升级到NavigationBar
但是,如果我将其添加到tableView.headView
,则可行
enter image description here
答案 0 :(得分:0)
试试这个:
添加此代码:
_searchBar.bounds = CGRectMake(0, 64, self.view.frame.size.width, searchBarH);
答案 1 :(得分:0)
我相信您在此处尝试将搜索栏添加到导航栏中。即使我之前遇到过类似的问题,我所做的就是创建了一个自定义视图,并在自定义视图中包含了搜索栏,然后将自定义视图添加到导航控制器。 我想你可能会发现下面的代码很有帮助。
[self.searchView addSubview:self.searchController.searchBar];
[self.navigationController.topViewController.view addSubview: self.searchView];