Rohit Singhal
Rohit Singhal

Reputation: 381

Button click not working when in presence of single Tap gesture

I have view hierarchy as follows

MyViewController --> ScrollView(added via IB) --> ImageView (+ zooming there) ---> button added on image View(added via code)

imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map.png"]];
[scroll addSubview:imageView];

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

myButton.frame = CGRectMake(660, 120, 40, 40);

[myButton setTitle:@"10" forState:UIControlStateNormal];

[myButton addTarget:self action:@selector(asiaPressed:) forControlEvents:UIControlEventTouchUpInside];

[myButton setEnabled:YES];
[imageView addSubview:myButton];

later on in view controller, i defined selector as

-(void) asiaPressed:(id)sender{
NSLog(@"asiaPressed clicked");

}

But it is never going inside selector..

Pls help...i guess it is very basic error..

Thanks in advance

Upvotes: 0

Views: 285

Answers (1)

Vladimir
Vladimir

Reputation: 170809

UIImageView has userInteractionEnabled property set to NO by default so it (and its subviews) does not receive touch events. You need to set that property to YES manually:

...
imageView.userInteractionEnabled = YES;
...

P.S. You also mention gesture recognizer in question title, however have not posted any code with it - so if it present it may also cause the problems, but the problem is most likely is what I described above

Upvotes: 1

Related Questions