Hiding the Keyboard when losing focus on a UITextView

Simplifying tuzzolotron’s answer:
Where the following outlet is properly connected in your xib

    IBOutlet UITextView *myTextView;

Use this in the view controller:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [[event allTouches] anyObject];
    if ([myTextView isFirstResponder] && [touch view] != myTextView) {
        [myTextView resignFirstResponder];
    }
    [super touchesBegan:touches withEvent:event];
}

A tap on the View Controller’s View, outside of the Text View, will resign the first responder, closing the keyboard.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)