我使用以下代碼來顯示一個UISearchBar與UISearchController
searchController = UISearchController(searchResultsController: resultsTableViewController)
searchController?.searchResultsUpdater = self
searchController?.searchBar.sizeToFit()
searchController?.searchBar.backgroundColor = UIColor.whiteColor()
searchController?.searchBar.searchBarStyle = UISearchBarStyle.Minimal
self.tableView?.tableHeaderView = searchController?.searchBar
searchController?.delegate = self
searchController?.dimsBackgroundDuringPresentation = false
searchController?.searchBar.delegate = self
definesPresentationContext = true
我的問題是,當我進入搜索模式時,進入視圖全屏和我可以看到的tableview的內容與重疊的UISearchBar這是這個問題的任何解決方案的錯誤?
見截圖
我的解決方案
func willPresentSearchController(searchController: UISearchController) {
topBarView = UIView(frame: CGRectMake(0.0, 0.0, self.view.frame.size.width, 20.0))
topBarView?.backgroundColor = UIColor.whiteColor()
AppDelegate.sharedAppDelegate().window?.rootViewController?.view.addSubview(topBarView!)
}
func willDismissSearchController(searchController: UISearchController) {
topBarView?.removeFromSuperview()
}
嘗試'self.automaticallyAdjustsScrollViewInsets = YES; ' – orkenstein 2015-02-11 08:01:26
它不適用於這個 – sger 2015-02-11 08:05:38
「紅色列表」是一個部分標題? – orkenstein 2015-02-11 08:12:40