问题
I want to build a search control like the maps app; the search opens a result tableview (which works fine) on iPhone and should open a tableview in a popover on iPad. This used to be automatic in UISearchDisplayController
but does not work anymore and it shows a fullscreen tableview on iPad.
self.resultsController = [[EFResultTableViewController alloc] init];
[self.resultsController.tableView setDelegate:(id<UITableViewDelegate>)self];
self.searchController =
[[UISearchController alloc] initWithSearchResultsController:self.resultsController];
[self.searchController setSearchResultsUpdater:(id<UISearchResultsUpdating>)self];
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.hidesNavigationBarDuringPresentation = NO;
[self.searchController.searchBar setBarTintColor:[UIColor whiteColor]];
[self.searchController.searchBar setDelegate:(id<UISearchBarDelegate>)self];
self.definesPresentationContext = YES;
ResultTableViewController
is just a customised tableview. I do not want to write IS_IPAD
conditional code. Is there anything I am missing here.
回答1:
THe solution was pretty simple, you need to set the style on the controller, it shows a normal list on iPhone and popover on iPad automatically.
[self.searchController setModalPresentationStyle:UIModalPresentationPopover];
来源:https://stackoverflow.com/questions/31378846/uisearchcontroller-showing-fullscreen-instead-of-a-popup-on-ipad