在用键盘单击“确定”按钮之前,如何在搜索栏中使用 uitextfield 获取字符?

发布于 2024-12-18 10:54:36 字数 335 浏览 5 评论 0原文

我有一个带有 UITextField 的 UISearchBar,当我用中文或日文向 UITextField 输入字母时,就像“w”一样,我发现键盘会显示一个面板,让用户选择一个中文单词,但在我选择一个之前word,我发现UITextField会显示字母“w”,而UISearchBarDelegate方法:

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

不会被调用,我想在使用键盘单击“确定”按钮或使用显示面板选择单词之前使用 UITextField 获取该字母。怎么办?非常感谢!

I have a UISearchBar with UITextField, and when I input a letter to the UITextField in Chinese or Japanese, just like "w", I found that the keyboard will show a panel which let user to choice a chinese word, but before I choice a word, I found that the UITextField will show the letter “w”, and the UISearchBarDelegate method:

-(void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText

not be called, and I want to get the letter with UITextField before I clicking the OK button with keyboard or choicing the word with showing panel. How to do? Thank you very much!

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

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

发布评论

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

评论(2

晨曦÷微暖 2024-12-25 10:54:36

方法?

- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

您是否尝试过 UISearchBarDelegate 协议中的

Have you tried the method

- (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text

in the UISearchBarDelegate protocol?

我做我的改变 2024-12-25 10:54:36

textField.delegate = self;

您需要设置委托,然后只有委托方法才会被调用。尝试一次!

textField.delegate = self;

You need to set delegate, then only delegate method will be get called. Try this once!!

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