0

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?

Chisx
  • 1,976
  • 4
  • 25
  • 53
Yony
  • 680
  • 1
  • 9
  • 20
  • 1
    There are probably other gesture recognizers interfering with it. Try setting your gesture recognizer's delegate, implementing all the delegate methods, and see which get called. – Aaron Brager Jan 26 '14 at 19:31
  • Why are you adding the gesture recognizer twice, once in the designated initializer of your derived class, and then again in the delegate method? – blackbird Jan 26 '14 at 21:29
  • I added again because I was desperate... Aaron, what you suggesting make sense... I will give it a chance – Yony Jan 28 '14 at 13:44

2 Answers2

1

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

Yony
  • 680
  • 1
  • 9
  • 20
0

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

n00bProgrammer
  • 4,261
  • 3
  • 32
  • 60
  • textFieldDidBeginEditing is not good for me because all my text fields is one letter textField - when you type a letter you automatocly jump to the next textField and I want to have a spcial logic when tapping on textfield – Yony Jan 28 '14 at 13:41