2015-07-13 70 views
0

我想構建一個像地圖應用程序一樣的搜索控件;搜索將在iPhone上打開一個結果tableview(這可以正常工作),並且應該在iPad上的彈出窗口中打開一個tableview。這曾經在UISearchDisplayController自動,但不再工作,它顯示在iPad上的全屏桌面視圖。UISearchController顯示全屏而不是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只是一個自定義的tableview。我不想寫IS_IPAD有條件的代碼。有什麼我在這裏失蹤。

回答

1

該解決方案非常簡單,您需要在控制器上設置樣式,它會自動顯示iPhone上的普通列表和iPad上的彈出窗口。

[self.searchController setModalPresentationStyle:UIModalPresentationPopover];