Remove Keyboard


/ Published in: iPhone
Save to your folder(s)

background tap - background should have type UIControl and method should be connected to the "touch down" action
textView - doesn't need to be connected to an action, but delegate needs to be connected to something that is a UITextViewDelegate
textField - delegate needs to be connected to something that is a UITextFieldDelegate and method should be connected to the "did end on exit" action


Copy this code and paste it in your HTML
  1. /*
  2.  * Gets rid of the keyboard when the user taps the background.
  3.  */
  4. - (IBAction) backgroundTap: (id) sender {
  5. [titleField resignFirstResponder];
  6. [description resignFirstResponder];
  7. }
  8.  
  9. /*
  10.  * Gets rid of the keyboard during edting when the "Return" key is pressed.
  11.  * (works for a UITextView)
  12.  */
  13. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range
  14. replacementText:(NSString *)text
  15. {
  16. if ([text isEqualToString:@"\n"]) {
  17. [textView resignFirstResponder];
  18. return FALSE;
  19. }
  20. return TRUE;
  21. }
  22.  
  23. /*
  24.  * Gets rid of the keyboard during edting when the "Return" key is pressed.
  25.  * (works for a UITextField)
  26.  */
  27. -(IBAction) textFieldDoneEditing:(id)sender {
  28. [sender resignFirstResponder];
  29. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.