隐藏搜索显示控制器的搜索栏 [英] Hide search bar of search display controller
问题描述
我将搜索栏和显示控制器拖动到视图控制器,并将其放在轮廓的底部.
I dragged a search bar and display controller to a view controller and placed it at the bottom of the outline.
然后我将其设置为显示在导航栏中,并在viewdidload中显示以下行.一切正常.
I then set it to display in navigation bar with following line in viewdidload. All that works.
self.searchDisplayController.displaysSearchBarInNavigationBar = true;
但是,我想首先将其隐藏,而vewdidload中的以下行没有任何作用.
However, I want to hide it initially, and the following line in vewdidload is not having any effect.
self.searchDisplayController.searchBar.hidden = true;
谁能建议该怎么做?
提前感谢您的任何建议.
Thanks in advance for any suggestions.
我想我发现您不能同时具有searchBar.hidden = true和displaySearchBarInNavigationBar.这对我来说很好,因为我只想要一个.因此,我尝试将这两种情况分开.
I think I have figured out that you cannot have searchBar.hidden = true and displaysSearchBarInNavigationBar at the same time. Which is fine by me as I only want one or the other. So I tried separating the two cases.
我认为
self.searchDisplayController.searchBar.hidden = true;
如果单独运行,它确实可以工作.
This does work if by itself.
然后,我有一个连接到操作方法的搜索按钮,如下所示:
Then I have a search button wired to an action method as follows:
- (IBAction)searchButtonPressed:(id)sender {
NSLog(@"search button pressed");
self.searchDisplayController.searchBar.hidden = false;
self.searchDisplayController.displaysSearchBarInNavigationBar = true;
self.searchDisplayController.searchBar.showsCancelButton = YES;
}
但是,尽管我从日志中看到该方法已被调用,但它并未取消隐藏搜索栏.也许这是委托人的问题,但仍在寻找解决方案.
However, while I can see from the log that the method is called, it does not unhide the search bar. Perhaps it is delegate issue but still looking for solutions.
推荐答案
做到这一点
- 从情节提要中将插座添加到searchBar
- 然后,您可以使用出口标识符通过添加以下行来隐藏searchBar
searchBar.hidden = true
这篇关于隐藏搜索显示控制器的搜索栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!