-7

What is the best most efficient way to implement a UISearchBar?

I check all over the internet, and all the tutorials are for the ios 7 version, and a lot of the methods are deprecated in ios 8. Can someone please provide a library, or a sample of how to implement a searchBar in xcode for ios 8?

Horray
  • 659
  • 9
  • 25
  • It is unclear what you are asking. Please ask a specific question, including applicable error messages - See http://stackoverflow.com/help/how-to-ask – Paulw11 Dec 24 '14 at 08:39
  • My question is What am I supposed to do about the deprecated codes when I implement the UISearchBar? I wrote deprecated at the parts that are deprecated. ex. self.searchDisplayController.searchResultsTableView – Horray Dec 24 '14 at 08:46
  • Have you looked at the documentation for the deprecated methods and properties. The documentation will normally provide the recommended alternative – Paulw11 Dec 24 '14 at 08:47
  • For example -http://stackoverflow.com/questions/25826332/searchdisplaycontroller-deprecated-ios-8 – Paulw11 Dec 24 '14 at 08:50
  • Yes I did look at the a number of times, and it does not give a clear answer. – Horray Dec 24 '14 at 08:58
  • 3
    It is pretty clear - Use `UISearchController` not `UISearchDisplayController`. If you are wanting to support versions prior to ios8 then you need to live with the deprecation warnings – Paulw11 Dec 24 '14 at 09:00
  • I understand and read that part previously, but I cant implement it in my code? ex.if (tableView == self.searchDisplayController.searchResultsTableView) { return [searchresultsArray count]; } else { return [array count]; } – Horray Dec 24 '14 at 09:03
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/67599/discussion-between-paulw11-and-mike). – Paulw11 Dec 24 '14 at 09:04

1 Answers1

1


I had to do the same you are doing a few months ago. So, I found this on GitHub: https://github.com/dempseyatgithub/Sample-UISearchController
Download/clone it and you'll be able to see how to use UISearchController with UITableView and UICollectionView. It has everything you need to upgrade from UISearchDisplayController to UISearchController. The UISearchController documentation is also really helpful.
If you also need to support iOS 7(something I personally recommend if you are really about to deploy your app to the App Store) do this:

if([UISearchController class]){
//Create an UISearchController and add it to your UITableViewController
}else{
//Create an UISearchDisplayController and add it to your UITableViewController 
}

Note: You'll have to do everything programatically if you want to support both versions of iOS.

Best regards,
Gabriel Tomitsuka

Gabriel Tomitsuka
  • 1,061
  • 10
  • 24