iOS 11: UISearchBar in UITableView header view overlaps content with scope bar

Originator:mrtom
Number:rdar://33682675 Date Originated:08/02/2017
Status:Open Resolved:
Product:iOS Product Version:11
Classification:Bug Reproducible:Yes
 
Using Xcode 9.0 beta 4 (but bug not present in iOS 10 or 9):

Create a UIViewController with a UISearchBar as it's header view. Setup several scope titles in the UISearchBar.

Click the search bar, and note than the scope buttons now appear, and they cover the top of the table view, obscuring the first row.

Rebuild on iOS 10 and note how this does not happen, the position of the table view contents is moved down below the header (in the y axis)

Comments

After two hours of searching, it’s not a bug.

Fixed by change this line:

tableView.tableHeaderView = searchController.searchBar

to

if #available(iOS 11.0, *) { navigationItem.searchController = searchController navigationItem.hidesSearchBarWhenScrolling = false } else { tableView.tableHeaderView = searchController.searchBar }

Reference here: https://stackoverflow.com/a/46351518/543296


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!