The reason your search bar scrolls with the contents of the table is because you placed it directly in the table, thereby making it a child of the table header. and this section ALWAYS scrolls ...
Here's how to achieve this. And it is actually quite simple. (The following example is based on a Storyboard, but the mechanism is the same that you use):
1) Use UIVIewController and NOT UITableViewController
2) Add a UITableView as a child of the parent UIView
3) Add the UISearchBarController also as a child of the UIView, NOT as a child of the UITableView (UITableView and UISearchController are siblings)
you should have the following layout:

EDIT: It is important to remember that the UISearchBarController ABOVE is a UITableView. Otherwise, you can see the UITableView overlap of the UISearchBarController when the latter is focused .
EDIT 2: BTW, if you use AutoLayout, be sure to set the TOP restriction of the View table relative to the SearchBar ...
Run it and enjoy the result.
Hope this helps.
Benjamin
source share