uitextfield hide keyboard?

送分小仙女□ 提交于 2019-11-30 15:56:59

问题


On the iphone. When I press on the uitextfield I don't want a keyboard to popup.

I want the same behavior, just no keyboard at all. How can I hide/close the keyboard when the user presses the uitextfield?


回答1:


If you want the exact same behavior, without the keyboard, try

textfield.inputView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];



回答2:


Returning NO to UITextFieldDelegate's - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField should do it.




回答3:


I think you can use

textfield resignFirstResponder

in delegate method -

(void)textFieldDidBeginEditing:(UITextField *)

textField like this:

-(void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField == yourTextField){
      [yourTextfield resignFirstResponder];
    }
}



回答4:


use this method to dismiss a keyboard touch anywhere in the view

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

or by clicking on keyboard done button

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


来源:https://stackoverflow.com/questions/5478719/uitextfield-hide-keyboard

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