隐藏UISearchBar取消按钮 [英] Hide UISearchBar Cancel Button

查看:536
本文介绍了隐藏UISearchBar取消按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UISearchDisplayController和UISearchBar通过Outlets从我的nib连接到我的ViewController。

I have a UISearchDisplayController and UISearchBar hooked up to my ViewController via Outlets from my nib.

我想隐藏取消按钮,它。问题是,下面的代码隐藏按钮,但只有在显示给用户一毫秒后(例如,它在模拟器和设备上闪烁,然后消失在视图之外)。

I'd like to hide the cancel button so that the user never sees it. The problem is that the following code hides the button, but only after displaying it to the user for a millisecond (e.g., it flashes on the simulator and device and then disappears out of view).

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller 
{
    controller.searchBar.showsCancelButton = NO;
}

有更好的方法隐藏它吗?

Is there a better way to hide it?

推荐答案

我设法通过继承 UISearchBar 并覆盖此方法:

I managed to hide the "Cancel" button by subclassing UISearchBar and override this method:

-(void)layoutSubviews{
    [super layoutSubviews];
    [self setShowsCancelButton:NO animated:NO];
}

这篇关于隐藏UISearchBar取消按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆