-3

Possible Duplicate:
Easy way to dismiss keyboard?

In view1, the keyboard gets shown. I want to dismiss the keyboard when i move to another view (view2). In view2, in the method that gets called when the view is shown, i try to do so:

[self endEditing:YES];

But this doesn't work, so i get the idea of catching the event (in View1) of a hidden view and dismiss the keyboard before moving to view2. Is this possible?

EDIT:

I think i need to clarify that view2 is not fully hidden when view1 is shown. It's 50 shown vertically.

As long as i work on view1, the Keyboard is shown and view2 is also shown (50%). view2 has a button, when i click on that button, i need to dismiss the keyboard (which is shown from view1).

I tried to mplement a method in view1 like so:

-(void)dismissKeyBoard{

[self endEditing:YES];
}

And call the method above in view2 when i click on the button but it doesn't work.

PS: The button i click in view2 will make view2 shows fully (100%) above view1.

Community
  • 1
  • 1
Malloc
  • 12,816
  • 31
  • 101
  • 184

1 Answers1

0

To dismiss the keyboard, you just have to "resignFirstResponder" on the input field that it is currently in. One easy way is to have a catch all method of all the input fields in your view.

So for example, I usually create a method like this:

-(void)dismissKeyboard {
  [self.textfield1 resignFirstResponder];
  [self.textfield2 resignFirstResponder];
}

then just call it before you transition

[self dismissKeyboard]
CocoaEv
  • 2,956
  • 18
  • 21
  • Hi, Thanx for you reply, problem is that view 2 is not fully hidden before transition, it's 50% shown. So the transition is not thrown from view1, but from view2 button. – Malloc Sep 10 '12 at 15:05