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

查看:23
本文介绍了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 头文件时,我注意到 _searchBarFlags 结构下的 autoDisableCancelButton 标志,但它是私有的.

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天全站免登陆