The delegate should implement gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: and return YES.
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?
解決
他のヒント
Is there a specific reason why you are using a UITapGestureRecognizer
? The UITextFieldDelegate
has a methods that are called whenever a textField
starts editing :
textFieldShouldBeginEditing:
textFieldDidBeginEditing:
Unless you have some code that conflicts with these methods, you do not need a UITapGestureRecognizer
所属していません StackOverflow