问题描述
当用户单击返回"按钮时,我想让键盘消失,有人告诉我使用
I want to make the keyboard disappear when the user clicks the "return" button, I was told to use
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
[tf resignFirstResponder];
return YES;
}
但是当我单击返回"按钮时没有任何反应,甚至没有调用该方法.我正在
But nothing happens when I click the "return" button, the method isn't even being called. I am doing this in
@interface gameOverMenu : UIView
不在ViewController中.我也不使用界面生成器.我该怎么办?
not in the ViewController. I also don't use interface builder. What should I do?
推荐答案
您需要确保实现UITextFieldDelegate并将UITextField委托设置为self.在您的.h文件中:
You need to make sure you implement the UITextFieldDelegate and set your UITextField delegate to self. In your .h file:
@interface gameOverMenu : UIView <UITextFieldDelegate>
.m文件中的某处(viewDidLoad:也许):
And somewhere in your .m file (viewDidLoad: maybe):
self.yourTextField.delegate = self;
现在,应调用-(BOOL)textFieldShouldReturn:(UITextField *)textField方法.
Now your -(BOOL)textFieldShouldReturn:(UITextField *)textField method should be called.
这篇关于不调用textFieldShouldReturn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!