使用UISearchController修复了UISearchBar - 不使用UITableView的标题视图 [英] Fixed UISearchBar using UISearchController - Not using header view of UITableView

查看:102
本文介绍了使用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;

这篇关于使用UISearchController修复了UISearchBar - 不使用UITableView的标题视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆