解决UISearchDisplayController 在消失后显示navigationController.navigationBar的问题

本人在做一个项目,在viewWillAppear已经加入了如下代码,
self.navigationController.navigationBar.hidden = YES ;

但是使用了UISearchDisplayController后,但是出现一个问题,就是在UISearchDisplayController消失后,navigationBar显示了。查找了API文档,找到这么一句话,

/* Displaying the search bar in a navigation bar will override the contentsController's navigationItem if it has one. */
@property (nonatomic, assign) BOOL displaysSearchBarInNavigationBar NS_AVAILABLE_IOS(7_0);

后来,又看到有这么一个属性,

@property(nonatomic,readonly)                                  UIViewController           *searchContentsController; // the view we are searching (often a UITableViewController)

于是,在代码里面加入如下语句,

_searchController.displaysSearchBarInNavigationBar = NO ;
_searchController.searchContentsController.navigationController.navigationBarHidden = YES ;

问题就解决了。

原因:在点击UISearchDisplayController中的查找输入框后,会弹出一个UITableViewController,而输入框会放在当前的ViewController中的navigationBar上面,所以导致了navigationBar显示。

**新发现: self.navigationController.navigationBarHidden = YES;
好像也能解决这个问题。**

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值