Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton (inside UIView) in UITableViewCell click event not working

enter image description here

The above image is UITableViewCell designer preview. Button (Refer 1) touch up inside event is working properly.

But, Button (Refer 2) touch up inside event not triggering. It is inside a view.

I disabled the UserInteractionEnabled property of Button(Refer 2)'s View.

But, No luck. Not working.

like image 429
sriman reddy Avatar asked May 23 '16 07:05

sriman reddy


2 Answers

your View height is 0 that's why you not able to tap it

to test it set clips to bound value to yes

and also you need to set height for your view to solve that issue

like image 121
Prashant Tukadiya Avatar answered Oct 22 '22 11:10

Prashant Tukadiya


1) In your cellForRowAtIndexPath: method, assign button tag as index:

cell.yourbutton.tag = indexPath.row;

2) Add target and action for your button as below:

[cell.yourbutton addTarget:self action:@selector(yourButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

3) Code actions based on index as below in ViewControler:

-(void)yourButtonClicked:(UIButton*)sender
{
     if (sender.tag == 0) 
     {
         // Your code here
     }
}
like image 21
Elangovan Avatar answered Oct 22 '22 11:10

Elangovan