Unable to customize the searchBar with UISearchController

Originator:me
Number:rdar://19577476 Date Originated:23-Jan-2015 10:47 AM
Status:Open Resolved:
Product:iOS SDK Product Version:8.1.2
Classification:UI/Usability Reproducible:Always
 
Summary:
I'm trying to subclass UISearchController to customize the searchBar. I want it to not show the cancel button. 
However, once I use this new subclass, searchResultsController controller is not presented and presentSearchController is not called if I implement it on the delegate.

Steps to Reproduce:
1. Open the attached project (created from https://developer.apple.com/library/ios/samplecode/TableSearch_UISearchController/Introduction/Intro.html) and available on https://www.dropbox.com/s/i9n46a87z3qgz4v/TableSearch.swift.zip?dl=0.

2. Run the project
3. Try to search
4. Observe that the results are not updated, because the view controller that filters them never gets presented!

PS: The relevant code is on MainTableViewController, mainly CustomSearchController and MainTableViewController.viewDidLoad()

Expected Results:
I’d expected that the UISearchController worked flawlessly and the searchBar cancel button was hidden.

Actual Results:
UISearchController doesn’t show at all.

Regression:
UISearchController is new on iOS 8. 

Notes:
1. The docs for UISearchController clearly recommends to subclass (https://developer.apple.com/library/prerelease/ios/documentation/UIKit/Reference/UISearchController/index.html#//apple_ref/occ/instp/UISearchController/searchBar). Quoting here:

“To create a custom UISearchBar, subclass the UISearchController class and return your custom object."


2. There’s a post on StackOverflow from an Apple iOS Frameworks Engineer stating that it’s a bug (http://stackoverflow.com/questions/25904213/custom-uisearchbar-with-uisearchcontroller/25940619#25940619).

3. I’d like to replicate the behavior from App Store.app on iPhone, where I have a tab just for search. Notice that it doesn’t show the cancel button in any button.

4. I can get the expected result by using UISearchDisplayController, which I believe is what App Store.app is using.

5. This bug was filled after DTS #616849108 (requested by the engineer involved).

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!