uitextfield hide keyboard?
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;
}
精彩评论