UITextView : How to hide keyboard

Hi ,

Anybody know how to hide keyboard for UITextView .

Regards
Rajan

MacBook, Mac OS X (10.5.2)

Posted on May 16, 2008 7:23 AM

Reply
13 replies

Jul 19, 2008 12:52 PM in response to objectuser

Ok here they are:

– textViewShouldBeginEditing:
– textViewDidBeginEditing:
– textViewShouldEndEditing:
– textViewDidEndEditing:
– textView:shouldChangeTextInRange:replacementText:
– textViewDidChange:
– textViewDidChangeSelection:

None of these will trigger when the user hits return. The first four trigger based on being assigned or resigned as the First responder and the last three trigger based on individual changes.

Jul 20, 2008 8:43 AM in response to StrangledSpyder

I don't know if this will work for you, but what I do in

textView:shouldChangeTextInRange:replacementText:

is check for [text isEqualToString:@"\n"] and then resign first responder. I'm using the standard keyboard, so in my case the "Done" key does induce this message, delivering @"\n".

Hope this helps,
Doug

Message was edited by: dredmuns

Message was edited by: dredmuns

Aug 15, 2008 6:33 PM in response to ThomasPa

Thanks for advice about looking for the carriage return. Here is my contribution. The UITextViewDelegate (which will be your custom subclass of a UIViewController) will implement this method.

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

The forum will not format the code correctly but anyway, hope you get the gist

Aug 16, 2008 1:59 AM in response to greenman2007

Maybe in the view controller implementation you can code as follows (of course change names to best fit your actual objects):

-(BOOL)textFieldShouldReturn:(UITextField *)theTextField{
if (nome==theTextField){
[nome resignFirstResponder];
}
return YES;

and of course in the header file declare something like this:

@interface testViewController : UIViewController <UITextFieldDelegate>

Hope this helps

(not sure about the forum formatting, hope you can figure out the right format anyway)

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

UITextView : How to hide keyboard

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.