First make sure, to add the UISearchBar to the tableHeaderView of the UITableView so that it gets scrolled with the table’s content and isn’t fixed to the top of the view.
The searchbar isn’t counted as a row in the tableview, so if you scroll the top of the tableview to the first row, it ‘hides’ the searchbar:
[yourTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
or in Swift:
yourTableView.scrollToRowAtIndexPath(NSIndexPath(forRow: 0, inSection: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)
Make sure to not scroll the tableview before it contains data (scrollToRowAtIndexPath
will raise an exception if the given indexPath does not point to a valid row (i.e. if the tableview is empty)).