如何使用UISearchBar启用取消按钮? [英] How to enable cancel button with UISearchBar?

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

问题描述

如果输入搜索字词,在iPhone上的联系人应用程序中,点击搜索按钮,键盘被隐藏,但取消按钮仍然启用。在我的应用程序中,当我调用resignFirstResponder时取消按钮被禁用。

In the contacts app on the iPhone if you enter a search term, then tap the "Search" button, the keyboard is hidden, BUT the cancel button is still enabled. In my app the cancel button gets disabled when I call resignFirstResponder.

任何人都知道如何在取消按钮处于启用状态的同时隐藏键盘?

Anyone know how to hide the keyboard while maintaining the cancel button in an enabled state?

我使用以下代码:

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
}

键盘滑出视图,但右侧的取消按钮搜索文本字段被禁用,因此我无法取消搜索。联系人应用程序将取消按钮维持在启用状态。

The keyboard slides out of view, but the "Cancel" button to the right of the search text field is disabled, so that I cannot cancel the search. The contacts app maintains the cancel button in an enabled state.

我认为可能有一种解决方案是潜入searchBar对象并在实际文本字段上调用resignFirstResponder,而不是搜索栏本身。

I think maybe one solution is to dive into the searchBar object and call resignFirstResponder on the actual text field, rather than the search bar itself.

任何输入值得赞赏。

推荐答案

尝试这个

for(id subview in [yourSearchBar subviews])
{
    if ([subview isKindOfClass:[UIButton class]]) {
        [subview setEnabled:YES];
    }
}

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

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