Detecting which UIButton was pressed in a UITableView

前端 未结 26 2957
小蘑菇
小蘑菇 2020-11-22 00:40

I have a UITableView with 5 UITableViewCells. Each cell contains a UIButton which is set up as follows:

- (UITableView         


        
26条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 00:58

    It works for me aswell, Thanks @Cocoanut

    I found the method of using the superview's superview to obtain a reference to the cell's indexPath worked perfectly. Thanks to iphonedevbook.com (macnsmith) for the tip link text

    -(void)buttonPressed:(id)sender {
     UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
     NSIndexPath *clickedButtonPath = [self.tableView indexPathForCell:clickedCell];
    ...
    
    }
    

提交回复
热议问题