取消按钮未显示在UISearchBar中 [英] Cancel button is not shown in UISearchBar
本文介绍了取消按钮未显示在UISearchBar中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有 UICollectionView
。点击 UINavigationBar
中的搜索按钮,我添加 UISearchController
的搜索栏
作为 UINavigationItem
的标题视图。对于iPhone它运作正常。对于iPad,取消
按钮不会显示。单独的搜索栏占据整个宽度。
I have UICollectionView
. On clicking search button in UINavigationBar
, I am adding the UISearchController
's searchbar
as titleview for UINavigationItem
. For iPhone it is working properly. For iPad the cancel
button is not shown. The Searchbar alone takes the entire width.
任何人都可以帮我解决这个问题吗?在此先感谢。
Can anyone help me out on this?. Thanks in advance.
推荐答案
iOS7在添加到导航栏时不显示取消按钮。您可以将搜索栏放在另一个视图中像这样。
iOS7 does not show the cancel button when added to a navigation bar.You can put searchbar in another view like this.
UISearchBar *searchBar = [UISearchBar new];
searchBar.showsCancelButton = YES;
[searchBar sizeToFit];
UIView *viewForSearchBar = [[UIView alloc]initWithFrame:searchBar.bounds];
[viewForSearchBar addSubview:searchBar];
self.navigationItem.titleView = viewForSearchBar;
这篇关于取消按钮未显示在UISearchBar中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文