ios
ios

Reputation: 6164

How to hide keyboard once UITextView becomes the first responder in iPhone SDK?

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.

Upvotes: 1

Views: 10388

Answers (6)

Hitesh Vaghela
Hitesh Vaghela

Reputation: 1635

   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];
     }
  }

Upvotes: 1

Steve Riggins
Steve Riggins

Reputation: 185

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;
}

Upvotes: 1

Swastik
Swastik

Reputation: 2425

 - (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...

Upvotes: 0

Ranjeet Sajwan
Ranjeet Sajwan

Reputation: 1921

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

Upvotes: 0

ipraba
ipraba

Reputation: 16553

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

Upvotes: 1

Miguel
Miguel

Reputation: 134

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

i think this can help you.

Upvotes: 2

Related Questions