我看到一些关于如何在UITextField失去焦点时关闭键盘的线程,但它不适用于我,我不知道如何。下面的代码中的“touchesBegan:withEvent:”永远不会被调用。为什么?UITextField失去焦点时隐藏键盘
- (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的子类,以便像我在其他线程中看到的那样使用此方法,但它可能有一个更简单的方法。
你能帮我吗?非常感谢!