Reputation: 338
I'm making a UITableView that displays a record of past events. It all looked great until I added a search bar at the top. It all looks how I want when it's scrolled to the top:
However, when I scroll to the bottom there's now a bunch of white space. It's hard to tell in this screenshot as there's no screen border but the tableview scroll will rest on this screen with about half the page blank:
Interestingly, when I activate the search bar at all (i.e. click in it and then press cancel) the white space goes away until this view appears again.
I've tried all sorts of settings for the tableView as well as using reloadData() at various stages of the view layout process to no avail. I know the number of rows is correct. The only thing I've found to make the white space go away is to disable the search bar. But I want the search bar!
Here's the code for the search bar:
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.searchBar.placeholder = "Search by keyword, name, etc."
controller.searchBar.barTintColor = UIColor(red: 224/256, green: 244/256, blue: 255/256, alpha: 1)
controller.searchBar.delegate = self
self.pastServicesTable.tableHeaderView = controller.searchBar
return controller
})()
Upvotes: 1
Views: 1584
Reputation: 123
I solved extra bottom space this way (in viewDidLoad):
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 200 // should be more than real row height will be
Upvotes: 1
Reputation: 34
Same thing happened to me. Stating the the tableview row height in the viewDidLoad (ie. self.tableView.rowHeight = 350) fixed it.
Upvotes: 1
Reputation: 136
It seems like you are observing UIKeyboardWillShowNotification
& UIKeyboardWillHideNotification
and changing the contentInset
of the tableView (adding keyBoard size height to contentInsets) and not setting the contentInsets to UIEdgeInsetsZero
when keyboard hides.
Upvotes: 0