1

In my iPhone App when I click on UITextView keyboard becomes visible

I try to use resignFirstResponder on "textDidEndOnExit" event but the keyboard does not hide.

What should be done to hide the keyboard?

please Help and Suggest, Thanks.

Code cracker
  • 3,105
  • 6
  • 37
  • 67
ios
  • 6,134
  • 20
  • 71
  • 103
  • possible duplicate of [how to hide the keyboard when empty area is touched on iphone](http://stackoverflow.com/questions/804563/how-to-hide-the-keyboard-when-empty-area-is-touched-on-iphone) – Grouchal Nov 19 '11 at 18:38

6 Answers6

2

Here another thread about this topic: how to hide the keyboard when empty area is touched on iphone

i think this can help you.

Community
  • 1
  • 1
Miguel
  • 134
  • 1
  • 12
1
   oneway, you can also hide keyboard when touch in view screen

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
      UITouch * touch = [touches anyObject];
      if(touch.phase == UITouchPhaseBegan) {
      [txtDetail resignFirstResponder];
     }
  }
Hitesh Vaghela
  • 1,635
  • 1
  • 11
  • 11
1

I would suggest you to keep a toolbar and inside a button called "Dismiss" just above the keyboard. resign your responder and hide the toolbar when dismiss button is clicked. In the textView textViewShouldBeginEditing show the toolbar. Default hide the toolbar.alt text

ipraba
  • 16,485
  • 4
  • 59
  • 58
  • How to add toolbar with dismiss button above the keyboard. Thanks for the input. – ios Dec 23 '10 at 12:39
  • its simple man. keep a toolbar in the center in Xib file and set it as hidden. add a UIbarbutton to the toolbar. Assign IBAction to the barbutton. Resign textview in that IBAction. – ipraba Dec 23 '10 at 12:46
1

If you want your UITextView to not allow carriage returns, and close when the user presses the return key (or Done if you have changed the return key type) then implement the UITextViewDelegate protocol and use something like:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
  if ([text isEqualToString:@"\n"]) {
      [textView resignFirstResponder];
      return NO;
  }
  return YES;
}
0

Make a UIButton or UiBarButton and assign it a method in which write [textView resignFirstResponder];

Ranjeet Sajwan
  • 1,925
  • 2
  • 28
  • 60
0
 - (BOOL)textViewShouldBeginEditing:(UITextView *)textView{


    return NO;
}

return No; wont allow your keyboard to appear.Hope it helps.You will not require any toolbar or something.Give it a try...

Swastik
  • 2,415
  • 2
  • 31
  • 61
  • He is asking about TextView not textField – Ranjeet Sajwan Dec 23 '10 at 12:48
  • thanx @Saawan I didnt noticed that – Swastik Dec 23 '10 at 12:51
  • In the question, it just asked to hide the keyboard .return No does the same thing.I have used it earliear also as I also met such a requirement.An please what is "aneneditable" – Swastik Dec 23 '10 at 13:14
  • @Swastik--It will better if you suggest him to just make the editable property of textView to NO.. Like [textView setEditable:NO ];.............Or try it from InterfaceBuilder at top of first property tab – Ranjeet Sajwan Dec 23 '10 at 13:19
  • Can anyone here let me know the reason for downvoting the answer.really not fair to downvote without adding any comment.. – Swastik Dec 24 '10 at 03:48
  • @Saawan why are you suggesting me what to do.You can suggest the person yourself.There are lot of ways to handle a single problem, that does not means only you are correct.. – Swastik Dec 24 '10 at 03:51
  • @Swastik -- Oh come on man....we are not here to fight....just suggesting him and you a better answer.....ok as you wish ....bye – Ranjeet Sajwan Dec 24 '10 at 04:55
  • @Raman, its no where mentioned in the question regarding that.Obviously ,when when you hide the keyboard how cant edit.What i understood from question is to hide keyboard on textview edit. – Swastik Dec 24 '10 at 04:55