iOS: Adding UISearchbar with filter Options in a t

2019-04-08 09:42发布

问题:

I am relatively new to iOS (coming from android background), and I would like to know how to implement and have a searchbar like in these two pictures http://i.stack.imgur.com/rQKE5.jpg and here(linkedin) http://i.stack.imgur.com/BnIG2.png . Would like to know how to make make the filters/options appear dynamicly when users clicks on search field and affect the results shown in the uitable. Example on linkedin 4 filters appear when user clicks on search. I have search on the net but I didn't manage to find persistent results. Again, what I want to know is how to show those options/filters when user click on searchbar

Any help is apreaciated, code or sample/ existing projects would be very useful.

Thank you all in advanced

回答1:

UIKit comes with a dedicated built-in solution for searching in conjunction with a UITableViewController, called UISearchDisplayController. It provides everything (albeit without much customization), including the search bar view, an optional scope bar for filtering, and transitions.

Reference: https://developer.apple.com/library/ios/documentation/uikit/reference/UISearchDisplayController_Class/Reference/Reference.html

Edit:

Here is a tutorial: http://www.appcoda.com/search-bar-tutorial-ios7/

And here is another one that includes a scope bar: http://www.raywenderlich.com/16873/how-to-add-search-into-a-table-view

Edit: All of this is obsolete now

iOS8 introduces a new class UISearchController to make this much cleaner. See http://useyourloaf.com/blog/2015/02/16/updating-to-the-ios-8-search-controller.html