如何使用情节提要引用UISearchController [英] How do you reference to a UISearchController using Storyboards

查看:57
本文介绍了如何使用情节提要引用UISearchController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了搜索栏&搜索显示控制器(假设这就是我在情节提要中添加的内容,因为它们没有要拖出的"SearchController"对象).

I've added a Search Bar & Search Display Controller (assuming that's what I add in storyboard since theirs no 'SearchController' object to drag out).

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

My issue is how do I set properties on that SearchController now? self.searchController doesn't work and Xcode says it's automatically added when I add the UISearchBar to the view. What am I doing wrong? The reason I need access it is so I can set the results search table, like so:

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

I noticed the example here: https://github.com/dempseyatgithub/Sample-UISearchController

这说它使用情节提要,实际上并没有使用情节提要添加到UISearchController中,而是通过分配,初始化和设置框架来使用代码.

Which says it uses storyboards, doesn't actually use storyboards for adding in the UISearchController, but uses code by allocating and initializing and setting the frame.

推荐答案

当您拖动搜索栏并将搜索控制器对象搜索到表视图上时,一个名为searchDisplayController的IBOutlet会自动添加到您的控制器中,而不是一个名为searchController的IBOutlet中.它还会为您设置数据源和委托.

When you drag the search bar and search Display controller object out onto your table view, an IBOutlet called searchDisplayController is automatically added to your controller, not one called searchController. It also sets the data source and delegate for you.

这篇关于如何使用情节提要引用UISearchController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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