0

我可能错过了一些东西......首先,我继承UITextField了一个 Tap 手势识别器并将其添加到UITextField(在指定的初始化程序中):

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


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

然后我将我的 viewController 设置为 textField 委托并实现了这个:

- (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;
}

从这一点开始,由于某种原因,pressed:在点击 textField 时不会被调用。任何想法为什么?

4

2 回答 2

1

代表应该实现gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:并返回YES。

于 2014-07-02T03:34:45.090 回答
0

您使用 a 是否有特定原因UITapGestureRecognizerUITextFieldDelegate有一个在textField开始编辑时调用的方法:

  • textFieldShouldBeginEditing:
  • textFieldDidBeginEditing:

除非您有一些与这些方法冲突的代码,否则您不需要UITapGestureRecognizer

于 2014-01-26T21:31:54.600 回答