Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search Results Visibly Scrolling Underneath the Status Bar

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.

Scrolling through search results

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.

Search results table view controller and its table view'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.

Search bar disappears

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

like image 362
Ryan Avatar asked Sep 30 '22 08:09

Ryan


1 Answers

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.

like image 64
Ryan Avatar answered Oct 03 '22 01:10

Ryan