不调用textFieldShouldReturn

编程入门 行业动态 更新时间:2024-10-23 21:37:10
本文介绍了不调用textFieldShouldReturn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

当用户单击返回"按钮时,我想让键盘消失,有人告诉我使用

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

本文发布于:2023-10-28 19:18:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1537543.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:textFieldShouldReturn

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!