使用 becomeFirstResponder 会导致取消按钮不起作用 [英] Using becomeFirstResponder causes cancel button to not work

查看:39
本文介绍了使用 becomeFirstResponder 会导致取消按钮不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UISearchDisplayController (searchDisplayCtr) 和一个 UISearchBar (searchBar).当我单击右侧字母表中的搜索图标时,我试图将焦点放在搜索栏上并调出键盘.如果我包括,

I have a UISearchDisplayController (searchDisplayCtr) and a UISearchBar (searchBar). I am trying to give focus to the search bar and bring up the keyboard when I click the search icon in the alphabet scroll on the right. If I include,

[self.searchDisplayCtr setActive:YES];
[self.searchDisplayCtr.searchBar becomeFirstResponder];

它会调出键盘并选择搜索栏,但取消按钮无法始终如一地工作.我曾尝试辞职第一响应者,在 searchDisplayControllerWillEndSearch 中将 active 设置为 NO 和两者,但它没有帮助.只有在字母卷轴上没有其他字母被点击的情况下,取消按钮才会起作用.

It brings up the keyboard and selects the search bar but the cancel button does not work consistently. I have tried resigning first responder, setting active to NO and both in searchDisplayControllerWillEndSearch, but it doesn't help. The cancel button will work only if no other letters on the alphabet scroll have been clicked yet.

推荐答案

在设置第一响应者之前,显然有必要向上滚动到表格顶部.代码最终是

It is apparently necessary to scroll up to the top of the table before setting first responder. The code ended up being

[tableView setContentOffset:CGPointMake(0, 0) animated:NO];
[self.searchBar  becomeFirstResponder];

这篇关于使用 becomeFirstResponder 会导致取消按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆