Search bar in UITableViewController header, without navigation controller, broken

Originator:luke
Number:rdar://15251290 Date Originated:17 Oct 2013
Status:Open Resolved:
Product:iOS SDK Product Version:7.0
Classification:UI/Usability Reproducible:Always
 
Summary:
If you have a UITableViewController, with a UISearchBar set as the tableViewHeader and managed by a UISearchDisplayController, if the controller's view fills the entire screen (e.g. it's the window's root view controller), when the search bar is activated, it correctly animates into place.

The above is also true if the UITableViewController is embedded within a UINavigationController - the navigation bar moves up and offscreen and the search bar moves into its place.

However, if you embed the UITableViewController in a custom container view controller using the view controller containment APIs, the search bar animation is glitchy and the search bar ends up in the wrong position.

Steps to Reproduce:
Please see the attached sample project.

1. Create a UITableViewController sub-class, and in viewDidLoad, create a search bar and assign it as the table view's header view.
2. Create a UISearchDisplayController to manage the search bar and configure the data sources and delegates as necessary to get the search working (not relevant to this bug).
3. Create a custom container controller - this could be something as simple as a root view with a container view inset from the screen edges (as in the sample app).
4. Initialise the UITableViewController sub-class and add it's view to the container view using the view containment APIs.
5. Set up constraints to ensure the UITableViewController's view fills the container view fully.
6. Tap the search bar and watch it break.

Expected Results:
For a normal search bar, with no scope selector, the search bar position or height should not change - the only thing that should happen is the "Search" prompt moves left, the Cancel button appears and the dimmer view appears below.

Actual Results:
What looks like a white container view appears around the UISearchBar, except it is too tall (the extra height appears to be equivalent to the status bar height), resulting in a white bar beneath the search bar when the animation begins.

Once the search bar animation completes, it shifts down 22 pixels, so the extra white space is now above the search bar. The search bar overlaps the top of the original table view (still visible beneath the dimmer view).

When there are search results, the search results table's top content inset correctly positions the first cell below the search bar, but the table view contents are visible in the white space above the search bar as it scrolls.

Version:
iOS 7 GM, Xcode 5

Notes:
No possible workarounds yet. I suspect this may be related to automatic handling of scroll view content insets.

Configuration:


Attachments:
'search-active.png', 'search-inactive.png' and 'SampleProject.zip' were successfully uploaded.

Comments

On further investigation, the use of a custom container appears be a red herring. My first statement in the original bug report was incorrect. It only behaves correctly when embedded in a UINavigationController.

Simply making the UITableViewController root view controller, results in a tableview/search bar view that underlaps the status bar (I believe this is expected behaviour) however activating the search bar still results in the same animation glitch. It's as if the UISearchDisplayController is accounting for the status bar even if my code is not. I've attached an updated sample project.

A workaround has been found; setting self.edgesForExtendedLayout to UIRectEdgeNone fixes this problem.

I'm unsure if this is a bug or I'm misunderstanding edgesForExtendedLayout or both. It's not very well documented.


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!