ios - 你如何使用 Storyboard引用 UISearchController

标签 ios objective-c uisearchbar uisearchcontroller

我已经添加了一个搜索栏和搜索显示 Controller (假设这是我在 Storyboard 中添加的内容,因为他们没有要拖出的“SearchController”对象)。

我的问题是现在如何在 SearchController 上设置属性? self.searchController 不起作用,Xcode 说当我将 UISearchBar 添加到 View 时它会自动添加。我究竟做错了什么?我需要访问它的原因是我可以设置结果搜索表,如下所示:

UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
 searchResultsController.tableView.dataSource = self;
 searchResultsController.tableView.delegate = self;

 self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];

self.searchController.searchResultsUpdater = self;

我注意到这里的例子:https://github.com/dempseyatgithub/Sample-UISearchController

说是用storyboard,其实并不是用storyboard来添加UISearchController,而是通过分配、初始化和设置frame来使用代码。

最佳答案

Important: UISearchDisplayController is deprecated in iOS 8. (Note that UISearchDisplayDelegate is also deprecated.) To manage the presentation of a search bar and display search results in iOS 8 and later, instead use UISearchController.

如官方文档中所述,最好停止将旧式 UISearchDisplayController 添加到针对 iOS 8.0+ 的应用程序。但他们似乎还没有从 Xcode6.1 的 UI Controller 库中删除旧的。他们也没有添加新的 UISearchController。让我们等待下一个补丁。

但是你仍然可以通过代码添加新的:

  _searchController=[[UISearchController alloc] initWithSearchResultsController:self];

关于ios - 你如何使用 Storyboard引用 UISearchController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26638587/

相关文章:

ios - 自定义 uitableviewcell 标签隐藏/显示

ios - 使用 CoreData/NSFetchedResultsController 使用来自 PrepareForSegue 的字符串填充 UISearchBar

iOS:如何通过一个 ibtool 命令使用本地化字符串文件本地化一堆 .xib 文件

ios - 如何在 swift 4 中将 GMSMapView 添加到 View 的一部分

javascript - 如何设置输入焦点?

IOS/objective-C/ Storyboard : Detect when show segue underway

ios - 删除应用程序并重新安装后,角标(Badge)计数会保留

ios - 如何让 UISearchController 开始隐藏?

ios - 单击搜索栏上的取消按钮时如何弹出自身 View Controller ?

ios - Xcode 从 10.2 降级到 10.1 后不显示模拟器