Search controller in navigation item in CollectionViewController doesn't work

Originator:craiggrummitt
Number:rdar://34257056 Date Originated:5 Sep 2017
Status:Open Resolved:
Product:UIKit Product Version:Xcode 9
Classification:Serious Bug Reproducible:Always
 
The new API in iOS 11 for embedding a search controller in a navigation item works great in view controllers and table view controllers, but only seems to work in Collection View Controllers when there are sufficient cells that the CVC requires scrolling.

Steps to Reproduce:
1. Set up a view controller, table view controller and two collection view controllers in the storyboard. 
2. Embed each in its own navigation controller.
3. Set up a custom class for each, and in each class do the bare minimum that should embed a search controller in the navigation bar, i.e.
 3.1. Create a search controller property:
`let searchController = UISearchController(searchResultsController: nil)`
  3.2. In the `viewDidLoad` method, embed the search controller in the navigation item:
`self.navigationItem.searchController = searchController`
4. Set both CVCs to return 1 section in the `numberOfSections` method.
5. To be able to see collection view cells, set their backgroundColor to red in the `cellForItemAt` method for both CVCs.
6. In the `numberOfItemsInSection` method, return a small number of cells in one CVC (eg. 10) and a large number of cells in the other CVC (eg. 1000)
4. Embed all four VCs in a Tab Bar Controller.

Expected Results:
The search controller should appear in the navigation bar for each of the four VCs.

Actual Results:
You will find that the search controller appears in the view controller and the table view controller and the collection view controller with a large number of cells, but does not appear in the collection view controller with a small number of cells.

Hypothesis is that when a CVC does not require scrolling it turns off some scrolling attribute that the search controller requires to animate on.

Version/Build:
Xcode 9 / iOS 11 / Swift 4

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!