在iOS中未调用textFieldShouldReturn [英] textFieldShouldReturn not being called in iOS
问题描述
我们正在尝试找出如何隐藏键盘,但是在触发textFieldShouldReturn
时遇到了问题.为什么?
We're trying to figure out how to get the keyboard to hide, but we're having problems getting the textFieldShouldReturn
to fire. Why?
这已完成:
*.h
@interface MultiSalesViewController : UIViewController <UITextFieldDelegate>
*.c
txtCardNumber.delegate = self;
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField setUserInteractionEnabled:YES];
[textField resignFirstResponder];
return YES;
}
此外,textField
在Interface Builder中将其委托设置为文件所有者".奇怪的是,viewController的- (void)textFieldDidEndEditing:(UITextField *)textField
正在工作.
Also, the textField
has its delegate set to Files Owner in Interface Builder. One odd thing, is that the viewController's - (void)textFieldDidEndEditing:(UITextField *)textField
is working.
如何使隐藏的键盘正常工作?
How to get the hiding of the keyboard working?
推荐答案
我遇到了完全相同的问题,这是因为我忘记将界面构建器中文本字段的委托设置为文件所有者".
I had the exact same issue and it was because I forgot to set the delegate for the text field in interface builder to 'files owner'.
这篇关于在iOS中未调用textFieldShouldReturn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!