gpt4 book ai didi

objective-c - UISearchBar 选择所有文本

转载 作者:可可西里 更新时间:2023-11-01 03:36:51 26 4
gpt4 key购买 nike

有什么方法可以选择 UISearchBar 中的所有文本吗?我尝试了 [searchBar selectALL:],但它抛出信号(无法识别的选择器)。

我想允许用户更改之前的搜索文本。在某些时候,当用户刚开始输入新请求时,旧请求应该被驳回。实现它的标准方法 - 在文本开始编辑时选择所有文本。

最佳答案

这可以使用标准的 UIResponder 语义来完成。无需深入研究 UISearchBar 的私有(private) View 层次结构。

[[UIApplication sharedApplication] sendAction:@selector(selectAll:) to:nil from:nil forEvent:nil]

您可以从任何地方调用它,selectAll: 选择器将运行响应链以查看是否有任何对象响应它。假设您的搜索栏当前是第一响应者(如果用户正在其中输入),它将响应并且结果将是所有选中的文本。如果不是,您可以通过在搜索栏上调用 becomeFirstResponder 使其成为第一响应者。

[_mySearchBar becomeFirstResponder]
[[UIApplication sharedApplication] sendAction:@selector(selectAll:) to:nil from:nil forEvent:nil]

关于objective-c - UISearchBar 选择所有文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8435271/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com