iPhone - 更改 UISearchDisplayController“取消”按钮文字

发布于 2024-09-18 05:50:48 字数 410 浏览 13 评论 0原文

排序问题: 有没有办法将 UISearchDisplayController 中的“取消”按钮文本更改为“完成”或“关闭”?

理由:

我有一个包含选项列表的 UITableView,每个选项都可以选中或取消选中。

我想通过这些选项启用搜索,因此我创建并添加了一个 UISearchDisplayController

用户将搜索项目,然后对搜索结果中的项目执行操作(即选择/取消选择某些项目)。

一旦完成,用户将返回到之前的(未搜索的)选项列表。

问题是关闭 UISearchDisplayController 的唯一方法是按“取消”按钮。然而,“取消”在这里是错误的词,因为在搜索栏中执行的操作将被存储。

因此,有没有办法将“取消”按钮文本更改为“完成”或“关闭”?

Sort question:
Is there a way to change the "Cancel" button text within a UISearchDisplayController to "Done" or "Close"?

Rationale:

I have a UITableView that contains a list of options, each option can be checked or unchecked.

I want to enable search through these options, so I've created and added a UISearchDisplayController.

The user will search for an item, and then perform actions on the items in the search results (i.e. will select/unselect certain items).

Once this is completed the user will then go back to the previous (unsearched) list of options.

The problem is that the only way to dismiss the UISearchDisplayController is to press the "Cancel" button. However "Cancel" is the wrong word here as the actions conducted while within the Search bar will be stored.

Therefore, is there a way to change the "Cancel" button text to "Done" or "Close"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

開玄 2024-09-25 05:50:48

我找到了一种方法来做到这一点,在搜索栏的委托中,创建一个空动画,然后在一小段时间后,更改按钮上的内容,这可能是因为取消按钮在调用委托后不久就会出现动画,因此你不能抓住它并在此之前更改它:

-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController*)controller {
[UIView
     animateWithDuration:0.05 animations:^{} completion:^(BOOL finished){

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

                //TODO:
                // do things with button here...
            }
        }
     }
     ];
}

I found one way to do this, in the delegate for the searchbar, create an empty animation then after a small duration, change your things on the button, this might be because the cancel button is animated in sometime shortly after the delegate is called, thus you cant grab it and change it before that:

-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController*)controller {
[UIView
     animateWithDuration:0.05 animations:^{} completion:^(BOOL finished){

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

                //TODO:
                // do things with button here...
            }
        }
     }
     ];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文