在哪里设置在UI Builder中创建的UISearchDisplayController的contentView [英] Where to set the contentView of UISearchDisplayController that was made in Interface Builder

查看:42
本文介绍了在哪里设置在UI Builder中创建的UISearchDisplayController的contentView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIToolbar中有一个UISearchBar,它与UISearchDisplayController绑定在一起.我希望UISearchDisplayController的结果显示在UISearchBar下方的弹出窗口中,但是我遇到了麻烦.我非常确定这是因为没有设置contentController,但是我找不到在哪里将contentsController分配给在Interface Builder中创建的UISearchDisplayController.我已经尝试过以编程方式进行创建,并调用initwithsearchbar:和contentscontroller:但是我认为,只有当我不想以编程方式创建搜索栏和控制器时,该方法才有效,

I have a UISearchBar in a UIToolbar that has a UISearchDisplayController tied to it. I would like the UISearchDisplayController's results to show in a popover below the UISearchBar but I'm having trouble with this. I'm pretty sure it's because there is not a contentsController set but I can't find where to assign a contentsController to a UISearchDisplayController that was created in Interface Builder. I've tried making it programatically and calling the initwithsearchbar: andcontentscontroller: but I think that will only work if the search bar and controller are created programatically which I don't want to do, any help would be awesome!

推荐答案

UISearchDisplayController仅使 与另一个UIViewController(如您提到的contentsController)一起使用.尽管它可以与任何 UIViewController一起使用,但它的主要用途(也是最不痛苦的用途)旨在与UITableViewController一起使用.

The UISearchDisplayController is made to only be used with another UIViewController (contentsController, as you mentioned). Though it can be used with any UIViewController, it's main use (and least painful use) is intended to be with a UITableViewController.

contentsController应该是负责管理要搜索的原始内容".如果控制器不管理项目集合,则无需搜索任何内容. UITableView是管理多个项目的主要标准控制器.

The contentsController is supposed to be "responsible for managing the original content to be searched". If the controller is not managing a collection of items, there's nothing to search. UITableView is the main standard controller that's managing multiple items.

如果您的UISearchBar位于UIToolbar中,则该工具栏可能位于由UIViewController管理的主视图中.如果您在运行时以编程方式访问readonly contentsController值,那就是我希望您能找到的.

If your UISearchBar is in a UIToolbar, the toolbar is likely in a main view that's managed by a UIViewController. If you programmatically access the readonly contentsController value at runtime, that's what i'd expect you to find.

Xcode4(可能还有InterfaceBuilder)会创建很多连接.他们现在指向UIViewController(文件的所有者?),并期望它实现UISearchBarDelegateUISearchDisplayDelegate协议中某些完全可选的方法.

Xcode4 (and likely InterfaceBuilder) creates a lot of connections when you just drop that search controller into the nib. They're now pointing at that UIViewController (the File's Owner?) and expecting it to implement some of the entirely optional methods in UISearchBarDelegate and UISearchDisplayDelegate protocols.

您可能想要实施

- (void)searchBar:(UISearchBar *)searchBar 
    textDidChange:(NSString *)searchText {
  // called when text changes (including clear)
  NSLog(@"[%@ %@]", NSStringFromClass([self class]), NSStringFromSelector(_cmd));
}

关于谜题contentsController并在每次键入文本时执行风选?

on the mystery contentsController and perform the winnowing each time text is typed?

(祝你好运)

我怀疑您可能根本不想在这个组合中使用UISearchDisplayController.

I suspect you may not want the UISearchDisplayController in the mix at all for this one.

这篇关于在哪里设置在UI Builder中创建的UISearchDisplayController的contentView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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