2016-04-09 158 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 
相关问题