UITextView resign first responder on 'Done' UITextView resign first responder on 'Done' objective-c objective-c

UITextView resign first responder on 'Done'


Implement the shouldChangeTextInRange: delegate method.

Use below approach and the solution work only with @"\n" (new line character).

//In you *.h file make sure you add@interface v1ViewController : UIViewController <UITextViewDelegate>- (void)viewDidLoad{    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.    myTextField.delegate = self;}    - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range           replacementText:(NSString *)text        {            if ([text isEqualToString:@"\n"]) {                [textView resignFirstResponder];                // Return FALSE so that the final '\n' character doesn't get added                return NO;            }            // For any other character return TRUE so that the text gets added to the view            return YES;    }


You can use the delegate method

- (void)textViewDidEndEditing:(UITextView *)textView {     [textView resignFirstResponder];}

You have to set your controller as the delegate for the TextView.For more methods you can have a look here: http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html%23//apple_ref/doc/uid/TP40006897