Swift 4: tableView and scopeButtons slide under searchBar in iOS 11

家住魔仙堡 提交于 2019-12-08 01:04:28

问题


I made an App in Swift 3 with a tableView that has a searchBar in its header. The searchBar also has a bar with a scopeButton. In iOS 10 the searchBar slid up to where the navigationBar was and everything worked fine. In iOS 11 however the tableView slides under the searchBar when it becomes active, so that the first cell is almost completely covered. When I now tap a cell to move to another View and go back, the scopeButton moved under the searchBar. Now the first cell is visible again but the distance to the searchBar is a little to big and of course the scopeButton is completely unusable. I also converted my project to Swift 4 but that didn't help. I'm using Xcode 9 GM and iOS 11 GM. This is my Code:

let searchController = UISearchController(searchResultsController: nil)

override func viewDidLoad() {
    super.viewDidLoad()

    UINavigationBar.appearance().titleTextAttributes = accordFont
    searchController.searchResultsUpdater = self
    searchController.dimsBackgroundDuringPresentation = false
    definesPresentationContext = true
    tableView.tableHeaderView = searchController.searchBar
    searchController.searchBar.barTintColor = UIColor(hue: 0.5, saturation: 0.43, brightness: 0.82, alpha: 1.0)
    searchController.searchBar.placeholder = "Suchen"
    self.navigationController?.navigationBar.barTintColor = UIColor(hue: 0.5, saturation: 0.43, brightness: 0.82, alpha: 1.0)
    searchController.searchBar.setValue("Abbruch", forKey:"_cancelButtonText")
    searchController.searchBar.delegate = self
    searchController.searchBar.scopeButtonTitles = ["Name", "Büro Nr.", "Mobil Nr.", "Abteilung"]
    searchController.searchBar.keyboardAppearance = .dark
}

And this is what it looks like when I tap the searchBar: Screesnhot

As you can see, the first cell is almost completely covered.

This is what happens when I click a cell while the searchBar is active and then go back to the tableView: Screenshot

来源:https://stackoverflow.com/questions/46192417/swift-4-tableview-and-scopebuttons-slide-under-searchbar-in-ios-11

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