当用户单击返回"按钮时,我想让键盘消失,有人告诉我使用
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
发布评论