I've an icon on leftView of textField and I want to add tap gesture to it. This is my code :
if (!textField.leftView){
UIImageView *infoImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 18)];
infoImage.image = [UIImage imageNamed:@"info"];
infoImage.contentMode = UIViewContentModeCenter;
textField.leftView = infoImage;
textField.leftViewMode = UITextFieldViewModeAlways;
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showErrorMessage:)];
tapRecognizer.numberOfTapsRequired = 1;
[infoImage addGestureRecognizer:tapRecognizer];
}
The problem when user click on the image on leftview nothing is happend and the showErrorMessage
is not called .
Update
The tap issue was solved by enabling userInteraction on the infoImage.
But now I'm getting [UITapGestureRecognizer tag]: unrecognized selector sent to instance
at second line of my Show errorMessage
:
-(void)showErrorMessage:(id)sender{
UIImageView *icon = (UIImageView *)sender;
NSString *key = [@(icon.tag) stringValue];
NSLog(@"%@", [_errorDictionary objectForKey:key]);
}
Missing infoImage.userInteractionEnabled = YES;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With