Gap above first table with using UISearchController

为君一笑 提交于 2019-12-12 23:23:15

问题


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.

  1. Screenshot showing gap between active search controller and first cell.
  2. Screenshot showing gap between inactive search controller and first cell.
  3. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!