Search code examples
objective-cuitextfieldfirst-responderresignfirstresponderbecomefirstresponder

When textfield become first responder, gesture recogniser not responding, even after resign


I've probably missed something... First, I inherited from UITextField and added a Tap gesture recogniser to a UITextField (in the designated initialiser):

UITapGestureRecognizer * ges = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pressed:)];
[self addGestureRecognizer:ges];


-(void)pressed:(id)sender
{
    didPressed = YES;
    [self becomeFirstResponder];
}

Then I set my viewController to be the textField delegate and implemented this:

- (BOOL)textField:(UIOneLetterTextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSLog(@"Key Pressed %@", string);
    textField.text = string;
    [textField resignFirstResponder];
     UITapGestureRecognizer * ges = [[UITapGestureRecognizer alloc] initWithTarget:textField action:@selector(pressed:)];
    [textField addGestureRecognizer:ges];
    [self gotoNextTextfield:textField.cellLoc];
    return NO;
}

From this point, for some reason, pressed: doesn't get called when tapping on the textField. Any Idea why?


Solution

  • The delegate should implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: and return YES.