title: ios/objective-c: Interaction of Button Action with Dismiss Keyboard
body: <p>For a login screen using Storyboard I have a button for Login.  However, when the user touches the button, frequently, what happens is the keyboard is dismissed, the view moves down and then the user has to tap a second time to trigger the button's action method.</p>
  
  <p>I think the issue may have something to do with the method being used to dismiss the keyboard, <code>self.view endEditing:YES</code>.  Or maybe the event attached to the action method for the button, <code>Touch Up Inside</code>.  Or maybe the code that makes the view move based on what field you are in (shown below).</p>
  
  <p>Can anyone suggest the right way to do this...IE when the user touches the button, the action method is called the first time.</p>
  
  <p>I still would like the keyboard dismissed if the user clicks somewhere OTHER than the button or inside another textfield.</p>
  
  <p>Thanks for any suggestions.</p>
  
  <pre><code>//method dismissing keyboard
  - (void) tapped
  {
      [self.view endEditing:YES];
  }
  </code></pre>
  
  <p>The event for the button's action method is <code>"Touch Up Inside"</code></p>
  
  <p>In addition, I am using the following code to make the view move up and down as needed based on the textfield you are in:</p>
  
  <pre><code>-(void)textFieldDidBeginEditing:(UITextField *)sender
  {
      [UIView beginAnimations:nil context:nil];
      [UIView setAnimationDuration:.3];
      [UIView setAnimationBeginsFromCurrentState:TRUE];
      if ([sender isEqual:_username]) {
      self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y -70., self.view.frame.size.width, self.view.frame.size.height);
             }
      else if([sender isEqual:_password]) {
           self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y -90., self.view.frame.size.width, self.view.frame.size.height);
      }
      else if([sender isEqual:_Email]) {
          self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y -110., self.view.frame.size.width, self.view.frame.size.height);
      }
  
      [UIView commitAnimations];
  
  
  }
  -(void)textFieldDidEndEditing:(UITextField *)sender
  {
      [UIView beginAnimations:nil context:nil];
      [UIView setAnimationDuration:.3];
      [UIView setAnimationBeginsFromCurrentState:TRUE];
      if ([sender isEqual:_username]) {
      self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y +70., self.view.frame.size.width, self.view.frame.size.height);
      }
      else if ([sender isEqual:_password]) {
          self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y +90., self.view.frame.size.width, self.view.frame.size.height);
      }
      else if ([sender isEqual:_Email]) {
          self.view.frame = CGRectMake(self.view.frame.origin.x, self.view.frame.origin.y +110., self.view.frame.size.width, self.view.frame.size.height);
      }
      [UIView commitAnimations];
  }
  </code></pre>