How to get the indexpath.row when an element is activated?

前端 未结 19 2287
梦如初夏
梦如初夏 2020-11-21 23:30

I have a tableview with buttons and I want to use the indexpath.row when one of them is tapped. This is what I currently have, but it always is 0

var point =         


        
19条回答
  •  悲&欢浪女
    2020-11-21 23:46

    I used convertPoint method to get point from tableview and pass this point to indexPathForRowAtPoint method to get indexPath

     @IBAction func newsButtonAction(sender: UIButton) {
            let buttonPosition = sender.convertPoint(CGPointZero, toView: self.newsTableView)
            let indexPath = self.newsTableView.indexPathForRowAtPoint(buttonPosition)
            if indexPath != nil {
                if indexPath?.row == 1{
                    self.performSegueWithIdentifier("alertViewController", sender: self);
                }   
            }
        }
    

提交回复
热议问题