我可能错过了一些东西......
首先,我从UITextField
继承并为UITextField
(在指定的初始化程序中)添加了一个Tap手势识别器:
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;
}
从这一点来看,由于某种原因,在点击textField时不会调用pressed:
。
任何想法为什么?
答案 0 :(得分:1)
代表应该实施 gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: 并返回YES。
答案 1 :(得分:0)
您使用UITapGestureRecognizer
的具体原因是什么? UITextFieldDelegate
有一个方法,只要textField
开始编辑就会调用:
textFieldShouldBeginEditing:
textFieldDidBeginEditing:
除非您有一些与这些方法冲突的代码,否则您不需要UITapGestureRecognizer