当我返回false时,为什么textFieldShouldReturn仍在工作? [英] Why textFieldShouldReturn is still working when i return false?

查看:98
本文介绍了当我返回false时,为什么textFieldShouldReturn仍在工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我隐藏了通过执行功能textFieldShouldReturn并在此函数内调用resignFirstResponder()按下的返回键上的键盘.它工作正常,但是当我在此函数中返回false时,键盘仍处于隐藏状态.现在,我不明白如果两种情况下都隐藏了键盘,返回truefalse有什么用?

I am hiding keyboard on return key pressed by implementing function textFieldShouldReturn and calling resignFirstResponder() inside this function. It works perfectly but when I return false in this function, still then keyboard is hiding. Now here I do not understand that what is use of returning true or false if keyboard is hiding in both case?

推荐答案

由于调用resignFirstResponder,键盘被关闭了.它与textFieldShouldReturn的返回值无关.

The keyboard is being dismissed due to the call to resignFirstResponder. It has nothing at all to do with the return value of textFieldShouldReturn.

根据我的经验,textFieldShouldReturn的返回值几乎没有用.在大多数情况下,返回true还是false都没关系.

In my experience, the return value of textFieldShouldReturn almost has no use. In the vast majority of cases it makes no difference whether you return true, or false.

我在testFieldShouldReturn的所有用法中都返回了false.如果返回true,并且您的textFieldShouldReturn实现将第一个响应者设置为UITextView,则文本视图最终会在其中添加换行符.从textFieldShouldReturn返回false确保不会发生这种情况.但这是基于几年前使用iOS 4或5的经验.我不知道最新版本的iOS是否还会发生这种情况.

I return false in all my uses of testFieldShouldReturn. If you return true and your implementation of textFieldShouldReturn sets the first responder to a UITextView, the text view ends up getting the newline added to it. Returning false from textFieldShouldReturn ensures this won't happen. But this was based on experience with iOS 4 or 5 a few years ago. I don't know if that still happens with the latest versions of iOS.

这篇关于当我返回false时,为什么textFieldShouldReturn仍在工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆