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
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)