try this
imgView.userInteractionEnabled = YES ;
userInteractionEnabled
of UIImageView
is set to NO by default.
Pergunta
I am creating several UIView
's which I add a UITapGestureRecognizer
with an action
thats suppose to call a method in the viewController
, but it doesn't seem to work.
-(void)setupFreeMoneyView {
NSArray *array = @[@"Facebook", @"Twitter", @"SMS", @"Email"];
int index = 0;
for (NSString *str in array) {
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(100*index++, 0, 100, 100)];
[imgView setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@Logo", str]]];
[imgView addGestureRecognizer:[[UITapGestureRecognizer alloc]
initWithTarget:self
action:NSSelectorFromString([NSString stringWithFormat:@"postTo%@", str])]];
[freeView addSubview:imgView];
}
}
freeView
is a UIView
created in the MainStoryboard
.
Ive checked if its the NSSelectorFromString()
by using a normal @selector()
thats not working but it isn't the cause.
It does work if I change the line [imgView addGestureRecognizer:...
to [freeView addGestureRecognizer:...]
I just don't seem to understand why this is happening.
Solução
try this
imgView.userInteractionEnabled = YES ;
userInteractionEnabled
of UIImageView
is set to NO by default.
Outras dicas
maybe you need set userInteractionEnabled = YES for the UIImageView