Detecting which UIButton was pressed in a UITableView

前端 未结 26 3377
小蘑菇
小蘑菇 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条回答
  •  南旧
    南旧 (楼主)
    2020-11-22 01:04

    Chris Schwerdt's solution but then in Swift worked for me:

    @IBAction func rateButtonTapped(sender: UIButton) {
        let buttonPosition : CGPoint = sender.convertPoint(CGPointZero, toView: self.ratingTableView)
        let indexPath : NSIndexPath = self.ratingTableView.indexPathForRowAtPoint(buttonPosition)!
    
        print(sender.tag)
        print(indexPath.row)
    }
    

提交回复
热议问题