Keyboard won't close with UITextField

微笑、不失礼 提交于 2019-12-13 05:42:05

问题


In my code I have:

-(BOOL)textFieldShouldReturn:(UITextField*)theTextField{

if (theTextField == ITload)
{
    [ITload resignFirstResponder];
    return  YES;
}

if (theTextField == FacilitiesLoad) {
    [FacilitiesLoad resignFirstResponder];
    return YES;
}
return NO;
}

ITload and FacilitiesLoad are both my text fields. I'm using Numerical with punctuation keyboard and no done key appears. I have a return key which doesnt close the keyboard down.

Any ideas on how to display a done key and to get textFieldShouldReturn working please?


回答1:


It seems that you haven't set the delegate of your text fields to your receiver.

ITLoad.delegate = self;
FacilitiesLoad.delegate = self;

EDIT: you're getting warnings because your view controller doesn't (formally) comforms to the UITextFieldDelegate protocol. Declare it like this:

@interface MyViewController: UIViewController <UITextFieldDelegate> {
}

etc.



来源:https://stackoverflow.com/questions/11818960/keyboard-wont-close-with-uitextfield

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!