开发者

uitextfield hide keyboard?

开发者 https://www.devze.com 2023-02-20 11:16 出处:网络
On 开发者_JAVA技巧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 press

On 开发者_JAVA技巧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?


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

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


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


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];
    }
}


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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消