开发者

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

开发者 https://www.devze.com 2023-02-06 04:40 出处:网络
How can I create a Spotlight-like search bar in an iP开发者_JS百科hone application?Just drag and drop a UISearchBar in Interface Builder and link it up as normal... Then you need some code to search y

How can I create a Spotlight-like search bar in an iP开发者_JS百科hone application?


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. There are numerous ways to do that, documented all over the internet. Google is your friend.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号