UISearchBar禁用取消按钮的自动禁用 [英] UISearchBar disable auto disable of cancel button

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

问题描述

我已经在表视图中实现了一个UISearchBar,除了一件小事之外几乎所有东西都在工作:当我输入文本然后按键盘上的搜索按钮时,键盘消失,搜索结果是显示的唯一项目表格,文本保留在UISearchBar中,但取消按钮被禁用。

I have implemented a UISearchBar into a table view and almost everything is working except one small thing: When I enter text and then press the search button on the keyboard, the keyboard goes away, the search results are the only items shown in the table, the text stays in the UISearchBar, but the cancel button gets disabled.

我一直试图让我的列表接近Apple联系人应用程序的功能当你在该应用程序中按搜索时,它不会禁用取消按钮。

I have been trying to get my list as close to the functionality of the Apple contacts app and when you press search in that app, it doesn't disable the cancel button.

当我查看UISearchBar头文件时,我注意到了autoDisableCancelButton下的一个标志。 _searchBarFlags结构但是它是私有的。

When I looked in the UISearchBar header file, I noticed a flag for autoDisableCancelButton under the _searchBarFlags struct but it is private.

当我设置UISearchBar时,是否有一些我缺少的东西?

Is there something that I am missing when I setup the UISearchBar?

推荐答案

我找到了解决方案。您可以使用此for循环遍历搜索栏的子视图,并在键盘上按下搜索按钮时启用它。

I found a solution. You can use this for-loop to loop over the subviews of the search bar and enable it when the search button is pressed on the keyboard.

for (UIView *possibleButton in searchBar.subviews)
{
    if ([possibleButton isKindOfClass:[UIButton class]])
    {
        UIButton *cancelButton = (UIButton*)possibleButton;
        cancelButton.enabled = YES;
        break;
    }
}

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

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