Search Bar does not display unless scope button titles set to empty array

Originator:keith
Number:rdar://20702394 Date Originated:26-Apr-2015
Status:Open Resolved:
Product:iOS SDK Product Version:8.3
Classification:Other Reproducible:Yes
 
Summary:
Using the iOS 8 UISearchController with a table view the search bar does not display if you are *NOT* using a scope bar unless the scopeButtonTitles property is set to an empty array.

Steps to Reproduce:
Using a simple table view controller app create a search controller in the viewDidLoad of the table view controller and add it to the table view header:

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
    self.searchController.searchResultsUpdater = self;
    self.searchController.dimsBackgroundDuringPresentation = NO;

    self.tableView.tableHeaderView = self.searchController.searchBar;
    self.definesPresentationContext = YES;


Expected Results:
The search bar should be shown in the header of the table view (without a scope bar)

Actual Results:
The search bar is not visible

Version:
iOS SDK 8.3

Notes:
See attached Xcode project to reproduce the problem. To workaround the problem set the scopeButtonTitles to an empty array:

self.searchController.searchBar.scopeButtonTitles = @[];

Configuration:
Xcode 6.3.1

Comments

Note that 'calling sizeToFit' on the search bar once it has been added to the view hierarchy didn't work for me. However, calling sizeToFit after all the subviews were laid out (i.e. in viewDidLayoutSubviews) worked.

sizeToFit

After some further digging the issue seems to be that the UISearchBar is not getting its size set correctly. The workaround is to to call sizeToFit on the search bar once it has been added to the view hierarchy:

[self.searchController.searchBar sizeToFit];


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!