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

前端 未结 19 2314
梦如初夏
梦如初夏 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

    In Swift 3. Also used guard statements, avoiding a long chain of braces.

    func buttonTapped(sender: UIButton) {
        guard let cellInAction = sender.superview as? UITableViewCell else { return }
        guard let indexPath = tableView?.indexPath(for: cellInAction) else { return }
    
        print(indexPath)
    }
    

提交回复
热议问题