当我在UITextField外部单击UITableView时,如何resignFirstResponder [英] How do I resignFirstResponder when I click outside of a UITextField onto a UITableView
问题描述
我无法让我的iPhone应用程序中的键盘消失,因为 UIView
即使在制作控制器时也无法触及,因为我有一个 UITableView
占用可用屏幕的其余部分。
I am having trouble getting the keyboard in my iPhone app to go away because the UIView
even when made a controller is not touchable because of the fact that I have a UITableView
taking up the rest of the available screen.
我很想知道如何通过点击<$ c $来辞去键盘又名 firstResponder
C>的UITableView ?有没有办法监视 UITableView
上的触摸事件,即使它不是要选择可点击的单元格。
I was curious to know how I would go resigning the keyboard aka firstResponder
by clicking onto the UITableView
? Is there a way to monitor a touch event on the UITableView
even if it is not to select a clickable cell.
基本上,我知道如果单元格触发事件,如何重新设置键盘,但是,如果我点击 UITableView的不可点击部分
我仍然希望键盘能够消失。
Basically, I know how to resign the keyboard if the cell fires the event but, if I click on a non - clickable part of the UITableView
I would still like the keyboard to go away.
推荐答案
2个选项:
- 在你的viewController中,响应表的滚动回调并重新响应响应者
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
[self.view endEditing:YES];
}
- 你可以随时在表/视图中添加 UITapGestureRecognizer 并从那里重新响应响应者
- You can always add a UITapGestureRecognizer to the table/view and resign the responder from there
我个人通常会这样做它在桌面滚动,因为我不喜欢单击以解除键盘。
Personally I usually do it on table scroll, since I don't like a single tap to dismiss the keyboard.
这篇关于当我在UITextField外部单击UITableView时,如何resignFirstResponder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!