Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the keyboard go away in the iphone simulator

Tags:

I've got one text entry box in my iphone app, when you touch it in the simulator, the keyboard pops up. But there's no way to get rid of it. Other web pages give solutions, without explaining why they should work, and they don't work for me. One says make the text box's delegate your uiview then call resignfirstresponder on the object, but it never gets called. Any suggestions? Can anybody explain what's actually going on? I can figure it out myself if I knew what the design paradigm was...

Maybe I should just put a "go" button so I have something to get the focus away from the textfield?

like image 595
stu Avatar asked May 05 '09 03:05

stu


2 Answers

One way to do it is to set an object as the delegate to the text field and implement

- (BOOL)textFieldShouldReturn:(UITextField *)textField 

in which you call [textField resignFirstResponder]

This will cause the keyboard to disappear when they push the return/go/done button (whatever you set the bottom right keyboard key to be).

See the UITextFieldDelegate reference for more info.

like image 171
Martin Gordon Avatar answered Nov 02 '22 23:11

Martin Gordon


To dismiss keyboard you can use TextField Delegate.

To use this follow these steps...
1. In you viewController.h add the delegate declaration like this:

@interface ViewController : UIViewController <UITextFieldDelegate> {     }
2. In your viewController.m call this method:
- (BOOL)textFieldShouldReturn:(UITextField *)textField
3. Then write a code like this:
- (BOOL)textFieldShouldReturn:(UITextField *)textField {     [textField resignFirstResponder];     return YES;     }
4. Final step is to set the textField's delegate:
- (void)viewDidLoad {         [super viewDidLoad];         self.textField.delegate = self;     }
like image 27
matteodv Avatar answered Nov 03 '22 00:11

matteodv