如何在iPhone应用程序中创建类似Spotlight的搜索栏? [英] How can I create a Spotlight-like search bar in an iPhone app?

查看:69
本文介绍了如何在iPhone应用程序中创建类似Spotlight的搜索栏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iPhone应用程序中创建类似于Spotlight的搜索栏?

How can I create a Spotlight-like search bar in an iPhone application?

推荐答案

将UISearchBar拖入IB并进行连接它到您的视图控制器。它需要一个委托才能起作用,因此,您可以使您的视图控制器符合UISearchBarDelegate协议,或者可以在数据层中进行搜索。但是最好的方法是使用UISearchDisplayController。委托以任何方式需要访问要搜索的数据,以便可以使用谓词来过滤数据。 这是 Apple的示例之一。

Drag a UISearchBar into IB and connect it to your view controller. It needs a delegate to function so, you could make your view controller conform to the UISearchBarDelegate protocol or you could do the searching in your data layer. But the best way is to use a UISearchDisplayController. Any way the delegate needs access to the data being searched so that it can use a predicate to filter the data. Here's one of Apple's examples of how to do this.

这篇关于如何在iPhone应用程序中创建类似Spotlight的搜索栏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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