Posted By

bethjt1220 on 04/29/11


Tagged

ios


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

shalomfriss


Remove Keyboard


 / Published in: iPhone
 

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

  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  

You need to login to post a comment.