使用UISearchController修复了UISearchBar - 不使用UITableView的标题视图

问题描述:

是否可以将UISearchController的UISearchBar放在除UITableView标题视图以外的地方?

Is it possible to put UISearchBar of UISearchController somewhere other than header view of UITableView?

苹果的UISearchController示例代码,使用以下内容。

[self.searchController.searchBar sizeToFit];
self.tableView.tableHeaderView = self.searchController.searchBar; 

是否有可能将searchBar定位在其他地方?
假设我们想要实现一个固定的UISearchBar,就像在联系人应用程序中使用的那样。
我试过这个但是搜索栏根本没有出现。

Is it possible to position searchBar somewhere else? Say we want to implement a fixed UISearchBar like the one used in contacts app. I've tried this but the searchBar doesn't appear at all.

你可以放置UISearchBar导航栏中的UISearchController使其保持固定

You can place the UISearchBar of UISearchController in the navigation bar so that it remains fixed

self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;

// Include the search bar within the navigation bar.
self.navigationItem.titleView = self.searchController.searchBar;

self.definesPresentationContext = YES;