UITextField and press gesture in LeftView
I have an icon in a leftView textField and I want to add a selection 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 is when the user clicks on the image on the left, nothing happens and is showErrorMessage
not called.
Update
The faucet issue was resolved by including userInteraction in the infoImage file.
But now I get [UITapGestureRecognizer tag]: unrecognized selector sent to instance
on the second line of my Show errorMessage
:
-(void)showErrorMessage:(id)sender{
UIImageView *icon = (UIImageView *)sender;
NSString *key = [@(icon.tag) stringValue];
NSLog(@"%@", [_errorDictionary objectForKey:key]);
}
+3
source to share