【发布时间】:2014-10-29 19:05:36
【问题描述】:
我添加了一个搜索栏和搜索显示控制器(假设这是我在情节提要中添加的,因为他们没有“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
它说它使用故事板,实际上并没有使用故事板来添加 UISearchController,而是通过分配和初始化和设置框架来使用代码。
【问题讨论】:
-
谢谢老板,如果你想把这个作为答案,我很乐意接受。
标签: ios objective-c uisearchbar uisearchcontroller