点击UIScrollView隐藏键盘? [英] Tapping a UIScrollView to hide the keyboard?

查看:246
本文介绍了点击UIScrollView隐藏键盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我之前曾匿名发布过此邮件,但后来无法再使用同一台计算机,所以现在我要从我的帐户中发布它.对不起,以前回答过的那个人.)

(I posted this before anonymously, but then couldn't use the same computer again, so I'm posting it from my account now. Sorry to the guy who answered before.)

我正在开发一个iPhone应用程序,该程序涉及在UITextView中键入内容,该UITextView将内容添加到UITableView.问题是,在用户完成操作后,我需要能够关闭键盘,而此时除了键盘和UITextView之外,唯一真正可见的区域是UITableView.我在实现UITableView上的touch事件时遇到了麻烦(例如,在任何地方都触摸UITableView,而不仅仅是didSelectRowAtIndexPath:).这是我在视图控制器中使用的代码,但是由于某种原因,它根本没有被执行:

I'm working on an iPhone app which involves typing stuff into a UITextView, which adds content to a UITableView. The problem is, I need to be able to close the keyboard when the user's done with it, and the only area that is really visible other than the keyboard and UITextView at this point is the UITableView. I'm having trouble implementing a touch event on the UITableView (as in, touching the UITableView anywhere, not just didSelectRowAtIndexPath:). Here's the code I'm using in the view controller, but for some reason, it's not being executed at all:

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
 [textView resignFirstResponder];
} 

有什么建议吗?

推荐答案

这是我在视图控制器中使用的代码"

"Here's the code I'm using in the view controller"

那是您的问题-您必须创建UITableView的子类并将函数放在其中,然后才能获得这些触摸事件.

That's your problem - you have to create a subclass of UITableView and put the function in there before you will get those touch events.

这篇关于点击UIScrollView隐藏键盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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