[英]How can I create a Spotlight-like search bar in an iPhone app?
如何在iPhone应用程序中创建类似Spotlight的搜索栏?
Just drag and drop a UISearchBar in Interface Builder and link it up as normal... Then you need some code to search your tableview/data. 只需在Interface Builder中拖放UISearchBar并将其正常链接即可...然后,您需要一些代码来搜索表格视图/数据。 There are numerous ways to do that, documented all over the internet.
有很多方法可以做到这一点,并在互联网上进行了记录。 Google is your friend.
Google是您的朋友。
Drag a UISearchBar into IB and connect it to your view controller. 将UISearchBar拖到IB中,并将其连接到视图控制器。 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.
它需要一个委托才能起作用,因此,您可以使您的视图控制器符合UISearchBarDelegate协议,或者可以在数据层中进行搜索。 But the best way is to use a UISearchDisplayController.
但是最好的方法是使用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.
这是苹果公司如何做到这一点的例子之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.