Reputation:
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=UITextFieldViewModeAlways;
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?
Upvotes: 3
Views: 1120
Reputation: 58087
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
Upvotes: 0
Reputation: 6066
On your UITextFieldDelegate, implement the method - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
and return NO
;
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return NO;
}
Upvotes: 3
Reputation: 9126
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 :)
Upvotes: 3