Ios7 如何将UISearchDisplayController与iOS 7中的条形按钮项集成

Ios7 如何将UISearchDisplayController与iOS 7中的条形按钮项集成,ios7,uinavigationcontroller,uibarbuttonitem,nsfetchedresultscontroller,uisearchdisplaycontroller,Ios7,Uinavigationcontroller,Uibarbuttonitem,Nsfetchedresultscontroller,Uisearchdisplaycontroller,到目前为止,我只熟悉UISearchDisplayController的一种实践,即将其与UISearchBar集成在tableView上。我看到一些应用程序在点击搜索栏按钮时会触发UISearchDisplayController,而不是触摸搜索栏。有人知道怎么做吗 通过在搜索栏的两个委托方法中编写以下代码,我找到了一个实现这一点的窍门 - (void)searchButtonTapped:(id)sender { self.dictionaryTableView.tableHeader

到目前为止,我只熟悉UISearchDisplayController的一种实践,即将其与UISearchBar集成在tableView上。我看到一些应用程序在点击搜索栏按钮时会触发UISearchDisplayController,而不是触摸搜索栏。有人知道怎么做吗

通过在搜索栏的两个委托方法中编写以下代码,我找到了一个实现这一点的窍门

- (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以确保搜索栏不会显示在屏幕上。

UISearchDisplayController本身不是一个界面项,那么您如何知道看到的是UISearchDisplayController?你到底看到了什么?为什么它不是一个界面?它包含一个搜索栏,一个我试图调用的表格视图[self.searchDC setActive:YES动画:YES];UISearchDisplayController按预期触发,但未显示搜索栏。UIDisplayController不包含搜索栏。您可以将其与搜索栏结合使用。它确实提供了一个表视图,这是真的;但我们只知道你看到了一个表视图,是吗?你还没有回答我关于你看到了什么的问题。我使用搜索栏初始化它,搜索栏使用_searchDC=[UISearchDisplayController alloc]initWithSearchBar:_searchbarcontents controller:self];