I inserted a text field into my application and now there is no way for the keyboard to close. How would I get the keyboard to close? Maybe by a button or clicking outside the textfield or something? Thanks!
Asked
Active
Viewed 239 times
0
-
3http://stackoverflow.com/questions/4761648/close-the-keyboard-on-uitextfield Maybe you want to check this out ;) – onigunn Aug 18 '12 at 15:59
-
Perhaps this might answer your question. http://stackoverflow.com/questions/5306240/iphone-dismiss-keyboard-when-touching-outside-of-textfield – Tanner Silva Aug 18 '12 at 15:59
3 Answers
1
Connect your button to an action and then add this line
[textField resignFirstResponder];

shabbirv
- 8,958
- 4
- 33
- 34
0
Say you have a textfield named myTextField, set the Delegate of the UITextField to your ViewController, add a referencing outlet between the File's Owner and the UITextField, then implement this method:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (textField == myTextField) {
[textField resignFirstResponder];
}
return NO;
}

Aniruddh
- 7,648
- 1
- 26
- 43
0
Just implement UITextFieldDelegate
protocol in your .h file and define
-- (BOOL)textFieldShouldReturn:(UITextField *)textField
delegate in your .m file as follows:
-- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
Most important do not forget to set delegate property of your UITextFiled Object "self" as:
m_txtTextFiled.delegate = self;
when u allocate its intance.

Spudley
- 166,037
- 39
- 233
- 307

Venu Gopal Tewari
- 5,672
- 42
- 41