我想向UISearchBar
而不是UIView
添加UIViewController
,问题是UISearchDisplayController
的init方法需要UIViewController
作为contentsController:
UISearchBar
。
我可以看到 self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
// this was my approach, but this DOES NOT work
UIViewController *results = [[UIViewController alloc] init];
results.view.userInteractionEnabled = NO;
[self insertSubview:results.view aboveSubview:self.menuList];
self.searchController = [[UISearchDisplayController alloc] initWithSearchBar:self.searchBar contentsController:results];
self.searchController.delegate = self;
self.searchController.searchResultsDataSource = self;
self.searchController.searchResultsDelegate = self;
self.tableView.tableHeaderView = self.searchBar;
在视图中正确显示,但如果我点击它,则栏会消失。这是我目前正在使用的代码:
{{1}}
在:
点击进入搜索栏后:
答案 0 :(得分:0)
在swift中,
我使用hidesNavigationBarDuringPresentation
来解决此问题。
此问题似乎在点击搜索栏后,它会自动隐藏栏。单击视图外部后会很好。
我添加这一行:
self.searchController?.hidesNavigationBarDuringPresentation = false;
希望它有效