如何从UITabBar控制器中的控制器使用UISearchDisplayController? [英] How to use UISearchDisplayController from a controller within an UITabBar controller?

查看:97
本文介绍了如何从UITabBar控制器中的控制器使用UISearchDisplayController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITabBar控制器管理多个控制器(使用SDK 3.0)。其中一个是tableView控制器,我需要使用UISearchDisplayController提供搜索功能。我的所有代码都基于Apple TableSearch示例。但是,单击选项卡时,tableView控制器将显示其相关内容,但不显示searchBar。我已经检查了IB中的xib以确保所有插座都已正确设置,但无论我尝试self.searchDisplayController始终为nil并且搜索栏没有出现。

I have an UITabBar controller managing several controllers (using SDK 3.0). One of these is a tableView controller and I need to provide a search capability using the UISearchDisplayController. All of my code is based on Apple TableSearch example. However, when clicking on the tab, the tableView controller appears showing its related content, but no searchBar appears. I have checked the xib in IB to make sure that all of the outlets are properly set, but no matter what I try self.searchDisplayController is always nil and the search bar does not appear.

实际上,我已经从TableSearch示例复制了MainView.xib,并将文件的所有者类设置为选项卡的正确控制器类。插座的设置与示例MainView.xib中的设置相同。我错过了任何重要的步骤或做错了吗?

In practice I have replicated MainView.xib from the TableSearch example and set the file's owner class to the correct controller class for the tab. The outlets are sets as in the example MainView.xib. Am i missing any important step or doing something wrong?

提前谢谢。

推荐答案

好的,我找到了解决方法。在我的情况下,问题是由于我使用嵌入在UITabBarController中的控制器作为其托管标签之一(即作为孩子)。

Ok, I have found how to solve it. In my case, the problem was due to the fact that I was using a controller embedded within the UITabBarController as one of its managed tabs (i.e. as a child).

删除来自UITabBarController的控制器,然后将UINavigationController添加到UITabBarController,最后将我的控制器作为UINavigationController的子项完全解决了这个问题。

Removing the controller from the UITabBarController, then adding an UINavigationController to the UITabBarController instead, and finally putting my controller as a child of the UINavigationController solved completely the issue.

我不明白为什么会这样(文档中没有相关信息,经常发生);然而,它现在就像一个魅力。
亲切的问候。

I do not understand why this is so (there is no related information in the documentation, as often happens); however, it now works like a charm. With kind regards.

这篇关于如何从UITabBar控制器中的控制器使用UISearchDisplayController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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