UISearchBarController iOS 11 issue - SearchBar and scope buttons overlap

后端 未结 7 860
误落风尘
误落风尘 2021-01-04 07:26

Referred here and here. No answer in first link. In the second link, though the answer is not accepted, but the link to apple developer forum gives error.

Before i

相关标签:
7条回答
  • 2021-01-04 07:58

    I had the same issue in iOS 11.

    Contrary to some of the comments here, if I look at your screenshots you DONT want to set it as the navigationItem because you don't have a UINavigationController setup.

    Neither do you want to add the searchBar in the header of the tableView because for some reason it can't cope with the scopeBar

    So what I did to fix it:

    To get a UISearchBar with scopes over your tableView, use a UIViewController in interface builder not a UITableViewController.

    Place a UISearchBar and a UITableView inside the view controller and wire them up properly (delegates, dataSource, etc).

    Don't forget to change your swift file to UIViewController instead of UITableViewController as well and change it accordingly. (add a tableView property and connect it via IBOutlet, change the delegates for the tableView etc)

    Then in interface builder, use autoLayout guides so the searchBar sits on top of the tableView

    In interface builder when you activate the scope bar it will look totally weird but don't panic, it will be fine. I guess Apple screwed the rendering n interface builder when they changed the behavior to work with UINavigationController... anyway...

    Then everything works as it should and look like this (in my case I present it the vc in a popover but that doesn't matter)

    0 讨论(0)
提交回复
热议问题