简体   繁体   English

UISearchController上的“取消”按钮有时不起作用

[英]Cancel button on UISearchController is not working sometimes

I am facing an issue with the UISearchController in iOS 8. The problem is that whenever I am clicking on cancel button, instead of cancelling the search operation, it is bringing up the keyboard. 我在iOS 8中遇到UISearchController的问题。问题是,每当我单击“取消”按钮而不是取消搜索操作时,它都会抬起键盘。 Follow below steps to reproduce the issue - 请按照以下步骤重现该问题-

  1. Click on the search bar. 点击搜索栏。
  2. Type a word and click on search(This will dismiss the keyboard) 输入一个单词并单击搜索(这将关闭键盘)
  3. Now click on cancel. 现在单击取消。

Now, instead of dismissing the search, the keyboard is popping up for entering the text. 现在,不是取消搜索,而是弹出键盘以输入文本。 This usually happens when I am tapping at the right half of cancel button and it can be reproduced even in standard iOS apps like Contacts app. 当我点击“取消”按钮的右半部分时,通常会发生这种情况,即使在标准的iOS应用(例如“通讯录”应用)中也可以重现该错误。 I would like to dismiss search when cancel is tapped. 点击取消时,我想关闭搜索。

Is there any workaround for this issue? 有没有解决此问题的方法?

单击取消按钮时,可以通过编程方式删除搜索栏作为第一响应者,以防止键盘弹起。

[searchController.textField resignFirstResponder];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM