How to resign or hide the keyboard?
I have a pick list to select a day and a text field to show the selected date. It will be like this...
If i choose any date, it will be like this....
The cross symbol in text field is acheived by the code....
textField.clearButtonMode=UITex开发者_开发技巧tFieldViewModeAlways;
Now my problem is, while clicking on this cross button, a keyboard was displayed. This is like....
But i want the cross button only for erase the text field. The keyboard should not come. Is it possible?
On your UITextFieldDelegate, implement the method - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
and return NO
;
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return NO;
}
In the textfield's 'Editing did begin' method, add the following:
[UITextField resignFirstResponder];
With this in place, that keyboard won't show up.
Happy coding :)
Try setting the editable property of that textfield to false.
As others have said, you can hide the keyboard through the UITextFieldDelegate protocol and through a [texfField resignFirstResponder]
method. Alternatively, as vfn suggested, you can prevent thE keyboard from showing altogether.
For that button though, you are young to want to set the clearButtonMode
property of the text field. To see what your available options are, read this: http://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextField_Class/Reference/UITextField.html#//apple_ref/doc/c_ref/UITextFieldViewMode
精彩评论