[英]How to show “Search Display Controller” using a button
I have a weird requirement, or at least something I have never done before... I have a UITableView
, the header of that table is a UISearchBar
. 我有一个奇怪的要求,或者至少是我以前从未做过的事情...我有一个UITableView
,该表的标题是UISearchBar
。 If you tap on that searchbar the "Search Display Controller" shows up and let you search... But now I need to remove that searchbar and call the "Search Display Controller" from a button. 如果您点击该搜索栏,则会显示“搜索显示控制器”,并让您进行搜索...但是现在我需要删除该搜索栏,然后从按钮中调用“搜索显示控制器”。
The problem is that if I remove the SearchBar when I call (from the button): 问题是,如果我在调用时(从按钮中)删除了SearchBar:
[self.searchDisplayController setActive:YES animated:YES]
I can't see the UISearchBar on top of the View. 我在视图顶部看不到UISearchBar。
I have no idea how to fix this... I have already tried: 我不知道如何解决此问题...我已经尝试过:
self.tableView.tableHeaderView = nil
in the viewDidLoad and when touching the button I set the UISearchBar as the table header again... it looks ugly and the animation is not smooth at all. self.tableView.tableHeaderView = nil
在viewDidLoad中,当触摸按钮时,我再次将UISearchBar设置为表格标题...它看起来很丑,动画一点也不流畅。 UISearchBar
gets first displayed in the header and the it's moved up to the top of the view... (我在tableview的标题中留出了一个空白空间),并且动画确实很糟糕,因为UISearchBar
首先显示在标题中,并且它向上移动到视图的顶部... Any help will be more than welcome!! 任何帮助都将非常受欢迎!! Thanks! 谢谢!
I realise that you have tried that, but thats the way we do it and it works: 我意识到您已经尝试过了,但这就是我们做到的方式,并且有效:
We add the UISearchBar into the view (not the table view). 我们将UISearchBar添加到视图(而不是表视图)中。 That being said you can't do that if you are using a UITableViewController. 话虽这么说,如果您使用的是UITableViewController,则无法执行此操作。 You have to add the tableView to a UIViewController. 您必须将tableView添加到UIViewController中。 Then we link it via an Outlet to the Controller and then set it to hidden in viewDidLoad: 然后,我们通过插座将其链接到控制器,然后将其设置为在viewDidLoad中隐藏:
self.searchBar.hidden = YES;
Then create a selector to show the searchBar again: 然后创建一个选择器以再次显示searchBar:
- (IBAction)search:(id)sender
{
self.searchBar.hidden = NO;
[self.searchBar becomeFirstResponder];
[self.searchDisplayController setActive:YES animated:YES];
}
Hope that helps. 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.