When performing a search on a dataset via a UISearchBar
, the search results successfully display in the UITableViewController
's UITableView
. However, when scrolling down through the results, the UITableView
's rows visibly appear underneath the UINavigationBar
and the simulator's status bar.
This obviously is not the look that I'm going for. Ideally, I would like the UISearchBar
to act as the UITableView
's header with all search results being contained below the UISearchBar
's scope buttons, but my attempts have been unsuccessful.
Below is the Storyboard setup of the relevant UITableViewController
and its UITableView
's properties.
Below is the relevant code that I am using to setup the UISearchController
and its UISearchBar
.
BallotTunesSearchTableViewController.h
@interface BallotTunesSearchTableViewController : UITableViewController <UISearchControllerDelegate, UISearchResultsUpdating, UISearchBarDelegate>
BallotTunesSearchTableViewController.m
- (void)viewDidLoad {
[super viewDidLoad];
self.appDelegate = [[UIApplication sharedApplication] delegate];
// Initialize the search controller
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
// Setup the search bar
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.scopeButtonTitles = [NSMutableArray arrayWithObjects:SongScopeName, ArtistScopeName, AlbumScopeName, nil];
self.tableView.tableHeaderView = self.searchController.searchBar;
}
Update: Note that the UITableViewController
is embedded in a UINavigationController
, and when setting the translucence of the UINavigationBar
to NO
, the UISearchBar
slides off the view along with the UINavigationBar
.
Also note that I am not implementing the UISearchBar
in Storyboard (however, I may take that route if I can't get my current setup to work).
After several face palms, it all came down to the lack of this line of code:
self.definesPresentationContext = YES;
Setting the presentation context to YES
indicates that the view controller's view should be covered when the view controller presents the UISearchController
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With