venkat
venkat

Reputation: 762

Button not responding to touch

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

Answers (4)

user529758
user529758

Reputation:

Because UIImageView has its userInteractionEnabled property set to NO by default. Set it to YES.

Upvotes: 3

SampathKumar
SampathKumar

Reputation: 2545

UIIMageView *image;
image.userInteractionEnabled=YES;

Upvotes: 0

Waseem Shah
Waseem Shah

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

Saqib Saud
Saqib Saud

Reputation: 2795

Make sure you have IBAction attached to your button. and then check if it has user interaction enabled.

Upvotes: 0

Related Questions