ios – UITextField并在leftView中点击手势

我在textField的leftView上有一个图标,我想为它添加点击手势.这是我的代码:

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

当用户点击leftview上的图像时,问题就出现了,并且没有调用showErrorMessage.

更新
通过在infoImage上启用userInteraction来解决tap问题.
但现在我得到[UITapGestureRecognizer标签]:无法识别的选择器发送到我的Show errorMessage的第二行的实例:

-(void)showErrorMessage:(id)sender{
UIImageView *icon = (UIImageView *)sender;
NSString *key = [@(icon.tag) stringValue];
NSLog(@"%@", [_errorDictionary objectForKey:key]);

}

最佳答案 缺少infoImage.userInteractionEnabled = YES;

点赞