I want to resign keyboard from UItextview. How to implement UItextView delegate method programmatically.
-
Possible duplicate of http://stackoverflow.com/questions/8871054/resign-keyboard-in-uitextfield – Emil Mar 16 '12 at 12:20
-
What exactly u want?? Please be specific.. – Krunal Mar 16 '12 at 12:26
-
There is no way of understanding what you are trying to do here. – Emil Mar 16 '12 at 12:31
-
How to implement delegate method which declare globally for my app? In my app keyboard did not resign when click on return. – gauri Mar 16 '12 at 12:42
-
My all textfield goes to upper when cursor move but textview not, it hide in back of keyboard – gauri Mar 16 '12 at 12:46
-
I can't understand what you are trying to say. – Emil Mar 16 '12 at 12:50
-
when cursor move on different textfield all textfield go to upper but when cursor go on textview, textview hide in back of keyboard how can solve this? emil understand or not – gauri Mar 16 '12 at 13:03
-
I have posted answer....try and reply if it helps u..:) – Krunal Mar 16 '12 at 13:08
-
Goti ji I am using textview not textfield – gauri Mar 16 '12 at 13:11
-
Oh sorry..I have edited my answer....:) – Krunal Mar 16 '12 at 13:16
-
And better to refer this....http://stackoverflow.com/questions/703754/how-to-dismiss-keyboard-for-uitextview-with-return-key – Krunal Mar 16 '12 at 13:23
-
Goti ji i also use this but not work – gauri Mar 16 '12 at 13:28
4 Answers
If u want that ur keyboard is resigned when click on return then u have to write, implement this method....
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
Just make it copy and paste....:)

- 1,318
- 1
- 13
- 31
Make sure you declare support for the UITextViewDelegate
protocol.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}
You should use the UITextViewDelegate. You have to declare the use of the protocol in your class header like:
@interface YourClass:NSObject<UITextViewDelegate>
Then in your .m, you should set your class as delegate in some point with something like:
textView.delegate = self;
Then, in your .m again, you have to implement the delegate methods, in particular:
textViewDidChange:
You can read the protocol reference at http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html for more information.

- 8,508
- 6
- 35
- 57
There is no specific delegate method for UITextview to know when user hits "RETURN" So you can do like this
//In .h File
@interface BlahBlah : UIViewController <UITextViewDelegate>
@property(nonatomic, retain) IBOutlet UITextView *myTextView;
@end
//In .m File
@implementation BlahBlah
@synthesis myTextView;
//In some method, can be viewDidLoad OR viewDidAppear . your convenience ;)
{
self.myTextView.delegate = self;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if([text isEqualToString:@"\n"]) {
[textView resignFirstResponder];
return NO;
}
return YES;
}

- 2,256
- 18
- 21