简体   繁体   中英

Dismissing UISearchController breaks grouped UITableViewController visual

I have a UITableViewController that shows countries group by the alphabet. I added a UISearchController in code:

let searchController = UISearchController(searchResultsController: nil)

searchController.searchBar.placeholder = ""
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar

The problem is that when I dismiss the search bar, the UI visual kind of breaks, showing a strange space above the search bar:

在此处输入图片说明

Any ideas why this happens and how to solve it?

Try adding:

searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.sizeToFit()

self.definesPresentationContext = true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM