Reputation: 762
In my application I added a UIImageview
to a UIView
and a UIButton
added to that UIImageView
. That button is not responding to touch events and the action selector is not called. Why?
Upvotes: 1
Views: 107
Reputation:
Because UIImageView
has its userInteractionEnabled
property set to NO
by default. Set it to YES
.
Upvotes: 3
Reputation: 2219
firstly you add imageview then add button then button is working properly like this code
UIView *AddView=[[UIView alloc]initWithFrame:CGRectMake(55, 0, 100, 100)];
UIImageView *imgview=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
UIButton *btnRemove = [[UIButton alloc]init];
UIImage *btnImage = [UIImage imageNamed:@"close.png"];
[btnRemove setImage:btnImage forState:UIControlStateNormal];
[btnRemove addTarget:self
action:@selector(btnREmoveAction:)
forControlEvents:UIControlEventTouchUpInside];
btnRemove.frame = CGRectMake(0,0, 29, 29);
btnRemove.tag=indexStart;
[AddView addSubview:imgview]; // add the imageview
[AddView addSubview:btnRemove]; // add the button
Upvotes: 0
Reputation: 2795
Make sure you have IBAction attached to your button. and then check if it has user interaction enabled.
Upvotes: 0