简体   繁体   中英

UIButton (inside UIView) in UITableViewCell click event not working

在此处输入图片说明

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.

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

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
     }
}

if you want to trigger action on button in uitableviewcell, You have to make sure that you added its trigger event programatically because each and every button perform diff events for that row data according to indexpath.

So in CellforRowatindexpath just write below changes

1.) Set indexpath.row as button tag to that button

2.) Assign trigger event programatically to that button.

Its work fine...if u not cleared let me know i will help you to out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM