UISearchDisplayController在代码中创建时无法正常工作? [英] UISearchDisplayController not working when created in code?

查看:98
本文介绍了UISearchDisplayController在代码中创建时无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用标签栏应用程序,其中一个标签有一个连接到UISearchBar的UISearchDisplayController。这一切都在NIB中连接起来并且正在运行。当我点击搜索栏时,范围和取消按钮会等等,搜索代理会正确更新结果表。

I'm working on a tab bar application and one of the tabs has a UISearchDisplayController hooked up to a UISearchBar. It's all connected up in the NIB and is working. When I tap the search bar, the Scope and Cancel buttons fly in etc, and the search delegate updates the results table correctly.

但是,我正在尝试实现 viewDidLoad 消息中的相同代码而不是NIB,但是当我从NIB中删除搜索显示控制器并取消注释我的代码以在函数中创建相同的控制器时,它不会不行。这就好像有一些基本的连接没有被创建,所以我的所有搜索代理功能都没有被调用。

However, I'm trying to implement the same code in the viewDidLoad message instead of the NIB, however when I delete the search display controller from the NIB and uncomment my code to create the same controller in the function, it doesn't work. It's as if there's some fundamental connection not being made so that all my search delegate functionality isn't being called.

这是我的工作 NIB版本搜索显示控制器。它连接到搜索栏, UINavigationController 子类( MASearchController ),并将其根视图连接到 searchContentsController

Here's my working NIB version of the Search Display Controller. It's hooked up to the search bar, the UINavigationController subclass (MASearchController) and the root view of that is hooked up as the searchContentsController.

替代文字http://img192.imageshack.us/img192/3050/screenshot20100307at304.png

现在这就是你所期望的在代码中创建相同的,对吧?我正在做的是将UISearchBar留在NIB中,以便在代码中一次消除一个拼图。

Now this is what you would expect to do in code to create the same, right? What I'm doing is leaving the UISearchBar in the NIB to eliminate one piece of the puzzle at a time in code.

// [MASearchController viewDidLoad]
UISearchDisplayController *searchController = [[[UISearchDisplayController alloc]
    initWithSearchBar:searchBar
    contentsController:[[self viewControllers] objectAtIndex:0]] autorelease];
[searchController setDelegate:self];
[searchController setSearchResultsDelegate:self];
[searchController setSearchResultsDataSource:self];

我在运行时检查了所有对象,但都检查了。基本上我已经从NIB中删除了搜索显示控制器,然后输入代码在 viewDidLoad 消息中创建它。

I've checked all objects at run time and they all check out. Essentially I've deleted the search display controller from the NIB and then put in the code to create it in the viewDidLoad message.

为什么这不起作用?搜索键盘出现但我的搜索和按钮动画功能都不起作用???

Why would this not work? The search keyboard comes up but none of my search and button animation functionality work???

推荐答案

哇,我刚想通了问题。

我想,因为UIViewController的searchDisplayController属性是在initWithSearchBar中设置的:contentsController:message我仍然会自动发布我的指针副本,但当我删除 autorelease 愚蠢的事情开始起作用。 Gaaaah。为什么它不会保留自己的副本(UIViewController)?

I figured, because the searchDisplayController property for the UIViewController is set inside the initWithSearchBar:contentsController: message I would still autorelease my copy of the pointer, but when I removed the autorelease the stupid thing started working. Gaaaah. Why would it not retain its own copy (the UIViewController)?

这篇关于UISearchDisplayController在代码中创建时无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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