当我返回false时,为什么textFieldShouldReturn仍在工作? [英] Why textFieldShouldReturn is still working when i return false?
问题描述
我隐藏了通过执行功能textFieldShouldReturn
并在此函数内调用resignFirstResponder()
按下的返回键上的键盘.它工作正常,但是当我在此函数中返回false
时,键盘仍处于隐藏状态.现在,我不明白如果两种情况下都隐藏了键盘,返回true
或false
有什么用?
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屋!