How to get indexPath when image inside cell tapped

前端 未结 5 1925
日久生厌
日久生厌 2020-12-06 23:29

I would like to implement feature that if profileImage tapped in tableviewCell, segue to detailView. I add tapGesture but I still can\'t figure out how to get indexPath to p

5条回答
  •  温柔的废话
    2020-12-07 00:05

    1: set tag of ImageView in cellForRowAtIndexpath method , tag will be equal to indexPath.row

    imgView.tag = indexPath.row
    

    2: add a target to tapGuestureRecognizer attached on imageView

    3: get tag of imageView in that method

    let imgView = sender as! UIImageView
    let tag = imgView.tag
    

    4: get data accordingly ,and push

    let next = self.storyBoard.instatiateViewController(WithIdentifer:"detailVC") 
    next.data = datas[tag]
    self.navigationController.pushViewController(next)
    

提交回复
热议问题