【发布时间】:2010-07-26 21:00:04
【问题描述】:
我已经看到一些关于如何在 UITextField 失去焦点时关闭键盘的线程,但它对我不起作用,我不知道如何。以下代码中的“touchesBegan:withEvent:”永远不会被调用。为什么?
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch = [[event allTouches] anyObject];
if ([self.textFieldOnFocus isFirstResponder] && [touch view] != self.textFieldOnFocus) {
[textFieldOnFocus resignFirstResponder];
}
[super touchesBegan:touches withEvent:event];
}
P.S.:此代码已插入到具有 UITableView 的视图控制器中。 UITextField 位于此表的一个单元格中。
所以,我的看法是:这个方法没有被调用,因为触摸发生在我的 ViewController 的 UITableView 上。所以,我认为,我应该将 UITableView 子类化,才能使用我在其他线程上看到的这种方法,但它可能有更简单的方法。
你能帮帮我吗?非常感谢!
【问题讨论】:
标签: iphone focus uitextfield