UISearchController searchbar hides the first cell in tableview

蹲街弑〆低调 提交于 2019-12-04 01:05:47

问题


I have a tableview with a search bar. The search bar is provided by a UISearchController. When I add the search bar to the header view of the table, the first row of the table gets covered by the search bar.

How do I prevent the search bar from hiding the first row?

I have this snippet in viewDidLoad:

self.searchController = UISearchController(searchResultsController: nil)
self.searchController.searchResultsUpdater = self
self.searchController.searchBar.delegate = self     
self.tableView.tableHeaderView = self.searchController.searchBar
self.searchController.dimsBackgroundDuringPresentation = false
self.searchController.searchBar.sizeToFit()

回答1:


It seems that you have to explicitly set the scope button titles array if you don't have scope button titles.

self.searchController.searchBar.scopeButtonTitles = [NSArray array];



回答2:


Found this issue to be a layout constraints issue. Resolved by dropping all of my constraints in the view containing my searchcontroller and adding back in individually until I found the offending constraint. Using Xcode 7.1



来源:https://stackoverflow.com/questions/30405321/uisearchcontroller-searchbar-hides-the-first-cell-in-tableview

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