我添加了一个搜索栏和搜索显示控制器(假设这是我在情节提要中添加的内容,因为它们没有可拖出的“SearchController”对象)。
我的问题是现在如何设置 SearchController 的属性? self.searchController 不起作用,Xcode 说当我将 UISearchBar 添加到视图时它会自动添加。我究竟做错了什么?我需要访问它的原因是这样我可以设置结果搜索表,如下所示:
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 https://github.com/dempseyatgithub/Sample-UISearchController
它说它使用故事板,实际上并不使用故事板来添加 UISearchController,而是通过分配、初始化和设置框架来使用代码。
重要提示:UISearchDisplayController 在 iOS 8 中已被弃用。(请注意,UISearchDisplayDelegate 也已被弃用。)要在 iOS 8 及更高版本中管理搜索栏的呈现并显示搜索结果,请改用 UISearchController。
正如官方文档中提到的,最好停止将旧式 UISearchDisplayController 添加到针对 iOS 8.0+ 的应用程序中。但似乎他们还没有从 Xcode6.1 中的 UI Controller 库中删除旧的。他们也没有添加新的 UISearchController。让我们等待下一个补丁吧。
但您仍然可以通过代码添加新的:
_searchController=[[UISearchController alloc] initWithSearchResultsController:self];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)