1

到目前为止,我只熟悉UISearchDisplayController的一个实践,它将它与放置在tableView上的UISearchBar集成。我看到一些应用程序单击栏按钮项时触发UISearchDisplayController而不是触摸searchBar。有没有人有任何想法如何做到这一点?如何将UISearchDisplayController与条形按钮项集成iOS 7

+0

本身的UISearchDisplayController不是一个接口项目,那么你如何知道你正在看到的是一个UISearchDisplayController?你看到了什么? – matt

+0

为什么它不是一个界面?它包含一个搜索栏,一个表格视图 – LongNV

+0

我试图调用 [self.searchDC setActive:YES animated:YES]; UISearchDisplayController按预期触发,但未显示搜索栏。 – LongNV

回答

0

我已想出一招被写做下面的搜索栏2种委托方法的代码

- (void)searchButtonTapped:(id)sender 
{ 
    self.dictionaryTableView.tableHeaderView = _searchBar; 
    [self.searchDC setActive:YES animated:YES]; 
    [self.searchDC.searchBar becomeFirstResponder]; 
} 

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar 
{ 
    [self.searchDC setActive:NO animated:YES]; 
    self.dictionaryTableView.tableHeaderView = nil; 
} 

的问题是UISearchDisplayController如果它的搜索栏没有的部分也不会出现SETACTIVE称为视图。因此,当点击按钮时,我将searchBar设置为tableViewHeader,并激活searchdisplaycontroller。然后当搜索结束时,我关闭searchdisplaycontroller,并设置nil tableViewHeader以确保搜索栏不会显示在屏幕上。