Search Results Visible Scroll Under Status Bar

When performing a dataset search using the UISearchBar the search results are successfully displayed in the UITableViewController UITableView . However, scrolling through the results, the UITableView lines are apparently displayed under the UINavigationBar and the simulator status bar.

Scrolling through search results

This is obviously not the look I am going to make. Ideally, I would like the UISearchBar act as the UITableView header with all the search results contained under the buttons in the UISearchBar , but my attempts were unsuccessful.

The following is a storyboard setting for the corresponding UITableViewController and its UITableView properties.

Search results table view controller and its table view's properties

Below is the relevant code that I use to configure UISearchController and 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; } 

Refresh . Note that the UITableViewController is built into the UINavigationController , and when setting the transparency from UINavigationBar to NO , the UISearchBar hides the view along with the UINavigationBar .

Search bar disappears

Also note that I do not implement the UISearchBar on the Storyboard (however, I can take this route if I cannot get my current setup to work).

+5
source share
1 answer

After a few facial palms, it all came down to the absence of this line of code:

 self.definesPresentationContext = YES; 

Setting the view context on YES means that the view controller view should be closed when the view controller presents the UISearchController .

+4
source

Source: https://habr.com/ru/post/1207614/


All Articles