简体   繁体   English

如何识别UITextFields和键盘活动?

[英]How to identify UITextFields and Keyboard Activity?

I've searched in the web but didn't found anything similar to what I want. 我在网上搜索过,但没有发现任何类似于我想要的东西。 So,I am creating an application and I need to recognize when the user leaves a specific UITextField,more clearly.when the user enters a value in the UITextField and after touch outside to dismiss the keyboard, I need to recognize that the UITextField has lost activity for,after I perform an action. 因此,我正在创建一个应用程序,我需要更清楚地识别用户何时离开特定的UITextField。当用户在UITextField输入值并在触摸外部以关闭键盘后,我需要认识到UITextField已丢失我执行某个动作后的活动。

Is this possible? 这可能吗?

Look up UITextFieldDelegate in the Apple docs. 在Apple文档中查找UITextFieldDelegate Specifically the methods textFieldDidEndEditing: and textFieldShouldReturn: . 特别是方法textFieldDidEndEditing:textFieldShouldReturn: . Hook up the specific UITextField to an outlet and assign its delegate to your viewController. 将特定的UITextField连接到插座并将其委托分配给viewController。 Then in the delegate method, if you need to make sure it's a specific text field, compare it to the IBOutlet. 然后在委托方法中,如果您需要确保它是特定的文本字段,请将其与IBOutlet进行比较。

write UITextFieldDelegate in .h file then after include the following method in .m file. 在.h文件中写入UITextFieldDelegate然后在.m文件中包含以下方法。

- (BOOL)textFieldShouldReturn:(UITextField *)textField 
{
    [textField resignFirstResponder];
    return NO;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM