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

问题描述

我已经实现了搜索栏,一旦用户在搜索栏中有焦点,就会显示取消按钮。为此,我在 searchBarTextDidBeginEditing 方法中编写了 searchBar.showsCancelButton = YES; 。在 searchBarSearchButtonClicked 中,我重新签名键盘,以便用户可以查看完整的tableview。

I have implemented searchbar which shows cancel button once user has focus in searchbar. For this I have written searchBar.showsCancelButton = YES; in my searchBarTextDidBeginEditing method. In searchBarSearchButtonClicked, I resign the keyboard so that user can view full tableview.

问题:此时搜索栏取消按钮没有响应。它只会在搜索栏再次获得焦点时响应。这是搜索栏取消按钮的默认属性还是我在代码中遗漏了一些东西。我想使用取消按钮而不再在搜索栏中给焦点。

Problem: At this point the searchbar cancel button is not responding. It only responds once searchbar gets focus again. Is this the default property of search bars cancel button or am I missing something in my code. I want to use cancel button without giving the focus in searchbar again.

推荐答案

这是搜索栏取消按钮的默认行为。如果您想要其他功能,可以取消选中搜索栏的cancelbutton属性,并可以使用 UIButton 作为取消按钮。

This is search bar cancel button's default behaviour. If you want other functionality, you can just uncheck cancelbutton property for search bar and can use UIButton as cancel button.

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

09-23 04:41