UISearchController showing fullscreen instead of a popup on iPad

穿精又带淫゛_ 提交于 2019-12-08 09:18:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!