UISearchController 在 iPad 上显示全屏而不是弹出窗口
UISearchController showing fullscreen instead of a popup on iPad
我想构建一个类似地图应用程序的搜索控件;搜索在 iPhone 上打开一个结果表视图(工作正常)并且应该在 iPad 上的弹出窗口中打开一个表视图。这在 UISearchDisplayController
中曾经是自动的,但不再起作用,它在 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_IPAD
条件代码。这里有什么我遗漏的吗?
解决方案非常简单,您需要在控制器上设置样式,它会在 iPhone 上显示普通列表,在 iPad 上自动显示弹出窗口。
[self.searchController setModalPresentationStyle:UIModalPresentationPopover];
我想构建一个类似地图应用程序的搜索控件;搜索在 iPhone 上打开一个结果表视图(工作正常)并且应该在 iPad 上的弹出窗口中打开一个表视图。这在 UISearchDisplayController
中曾经是自动的,但不再起作用,它在 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_IPAD
条件代码。这里有什么我遗漏的吗?
解决方案非常简单,您需要在控制器上设置样式,它会在 iPhone 上显示普通列表,在 iPad 上自动显示弹出窗口。
[self.searchController setModalPresentationStyle:UIModalPresentationPopover];