Using parameters in action of UITapGestureRecognizer in Swift

前端 未结 5 921
情深已故
情深已故 2021-02-04 04:00

I am trying to call a function with parameters using the action of UITapGestureRecognizer and I can\'t figure out any alternative.

This here is the gesture

5条回答
  •  孤街浪徒
    2021-02-04 04:11

    The Best way to achieve what you wish is get the superview of your tap gesture, this will give you the correct indexPath. Try this:

       func doubleTap(sender: UITapGestureRecognizer) {
            let point = sender.view
            let mainCell = point?.superview
            let main = mainCell?.superview
            let cell: myViewCell = main as! myViewCell
            let indexPath = collectionView.indexPathForCell(cell)
        }
    

    You can increase or reduce the superview's depending on you hierarchy level.

提交回复
热议问题