2016-04-09 162 views
0

我的應用需要支持通用設備。搜索欄的「取消」按鈕在iPad中消失

而且,在那裏,有一個視圖控制器有UISearchController。它可以在iPhone設備上正常顯示,但在iPad中,「取消」按鈕消失。

iPhone

iPad

它是關於搜索欄在視圖控制器,以下相關的代碼。

func configureSearchController() { 
    self.collectionView!.updateConstraints() 
    resultsTableController = SearchBookResultTableViewController() 
    resultsTableController.tableView.delegate = self 
    searchController = UISearchController(searchResultsController: resultsTableController) 
    searchController.searchResultsUpdater = self 
    navigationItem.titleView = searchController.searchBar 
    searchController.searchBar.sizeToFit() 
    searchController.dimsBackgroundDuringPresentation = false 
    searchController.hidesNavigationBarDuringPresentation = false 
    searchController.searchBar.delegate = self 
    searchController.searchBar.searchBarStyle = .Minimal 
    searchController.searchBar.placeholder = "書籍、作者、出版社" 
    // stress 
    searchController.searchBar.showsCancelButton = true 
    definesPresentationContext = true 
} 

我想知道問題的原因,以及我能以哪種方式解決它。

尋求幫助!謝謝。

+0

這是一個猜測 - 嘗試移動.sizeToFit前.showsCancelButton() –

+0

@MikeTaverne我嘗試用自己的方式,問題依然存在。 'showsCancelButton'屬性是'true',這是默認值。我只想強調屬性是真實的,所以我寫了它。 *>。<* –

+0

由於iPad鍵盤上有「鍵盤解除」按鈕,取消按鈕並不是必須的。 – tktsubota

回答

1

我在這個link的iOS 7中發現了相同的情況。我用同樣的方式解決我的問題。但是我不知道爲什麼,創建一個新的UIView,能解決嗎?他們之間有什麼不同?

self.collectionView!.updateConstraints() 
resultsTableController = SearchBookResultTableViewController() 
resultsTableController.tableView.delegate = self 
searchController = UISearchController(searchResultsController: resultsTableController) 
searchController.searchResultsUpdater = self 
searchController.searchBar.sizeToFit() 
searchController.dimsBackgroundDuringPresentation = false 
searchController.hidesNavigationBarDuringPresentation = false 
searchController.searchBar.delegate = self 
searchController.searchBar.searchBarStyle = .Minimal 
searchController.searchBar.placeholder = "書籍、作者、出版社" 

let SearchView: UIView = UIView(frame: searchController.searchBar.bounds) 
SearchView.addSubview(searchController.searchBar) 

navigationItem.titleView = SearchView 
相關問題