问题
I am not able to remove gap over first table row when testing with iOS 10.3. I tried all solutions suggested on other posts like automaticallyAdjustsScrollViewInsets
, added a dummy view above UITableView in hierarchy, e.g. here - but all without success.
Here is the setup and scenario.
I have a UIViewController that has UITableView. Calling it V1. it is embedded in a nav controller.
I am adding UISearchController in viewDidLoad() to tableview header. I am not setting any constraints not controlling any layout programatically.
self.searchController.obscuresBackgroundDuringPresentation = false
self.searchController.hidesNavigationBarDuringPresentation = true
if #available(iOS 11.0, *) {
self.searchController.searchBar.delegate = self
self.navigationItem.searchController = self.searchController
self.navigationController?.navigationBar.prefersLargeTitles = true
self.searchController.searchBar.scopeButtonTitles = ["All","A","B"]
self.navigationItem.hidesSearchBarWhenScrolling = true
} else {
self.searchController.searchBar.delegate = self
self.searchController.searchBar.scopeButtonTitles = ["All","A","B"]
tableView.tableHeaderView = searchController.searchBar
self.searchController.searchBar.sizeToFit()
}
I have another VC (a table) from which i capture data using unwind segue. Calling it V2.
i do the below in unwind method
DispatchQueue.main.async {
self.searchController.searchBar.text = searchText
self.searchController.isActive = true
let scope = self.searchController.searchBar.scopeButtonTitles![self.searchController.searchBar.selectedScopeButtonIndex]
self.filterContentForSearchText(searchText, scope: scope)
}
Scenario 1 - works fine 1. Opening V1 displays rows and search bar accurately in table header. 2. Tap on bar button that opens V2 3. Select a value and return 4. Returned value is assigned to search bar and search bar opens in navigation bar 5 Table shows rows that matches returned value from V2 There is no gap between first row and search bar
Scenario 2 - that fails. 1. Opening V1 displays rows and search bar accurately in table header. 2. Scroll the rows up such that header goes under navigation bar 3. Tap on bar button that opens V2 4. Select a value and return 5. Returned value is assigned to search bar and search bar opens in navigation bar 5 Table shows rows that matches returned value from V2
issue in this scenario is gap appear between first row and search bar. if i tap cancel button on search bar then search bar is restored on top of table but there is gap between searchbar ie header row and navigation bar.
I noticed that tableview's origin is -88 when above happens.
i tried setting table view top constraint to both superview ie View and bottom of top layout guide.
What could be the issue? screenshots attached.
- Screenshot showing gap between active search controller and first cell.
- Screenshot showing gap between inactive search controller and first cell.
- Visual debugger showing ViewController view in orange, tableview in green and header view in flat plum. There is a view above first cell that i have selected. Don't know what it is but is it causing the problem? A view there at bottom table also.
Thanks Ashish
来源:https://stackoverflow.com/questions/50696894/gap-above-first-table-with-using-uisearchcontroller