Rajkanth
Rajkanth

Reputation:

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...

alt text

If i choose any date, it will be like this....

alt text

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....

alt text

But i want the cross button only for erase the text field. The keyboard should not come. Is it possible?

Upvotes: 3

Views: 1120

Answers (4)

Moshe
Moshe

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

vfn
vfn

Reputation: 6066

On your UITextFieldDelegate, implement the method - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField and return NO;

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return NO;
}

Upvotes: 3

Aurum Aquila
Aurum Aquila

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

hotpaw2
hotpaw2

Reputation: 70693

Try setting the editable property of that textfield to false.

Upvotes: 1

Related Questions