Search code examples
iosobjective-cresignfirstrespondertpkeyboardavoiding

unrecognized selector sent to instance resignFirstResponder


I'm using TPKeyboardAvoiding in my app to hide move text fields when the keyboard is showing, but I'm getting an exception when I try to end editing the text field. It's coming from this method in TPKeyboardAvoiding:

- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    UIView* view =[self TPKeyboardAvoiding_findFirstResponderBeneathView:self];
    NSLog(@"%@",[view description]);
    [view resignFirstResponder]; //this line gives the exception
    [super touchesEnded:touches withEvent:event];
}

I'm a bit confused here. Shouldn't all UIViews respond to resignFirstResponder? Thanks for the help.

Full error:

2014-03-25 17:40:39.919 Rysk[5553:70b] -[MenuViewController textFieldDidBeginEditing:]: unrecognized selector sent to instance 0xb63c820

Solution

  • I solved the problem by having my view controller than contains the TPKeyboardAvoidingScrollView implement the UITextFieldDelegate protocol. Most importantly, these two methods:

    - (void)textFieldDidBeginEditing:(UITextField *)textField{}
    - (void)textFieldDidEndEditing:(UITextField *)textField{}