首页 > 解决方案 > 检测在“单元”上单击了哪个“视图”

问题描述

当我单击单元格上的任何 UIImageView 时,我有三个UIImageView单一Cell的,我想检测单击了哪个onCellSelection,而不UITapGestureRecognizer在每个单元上放置一个UIImageview

func SocialViewRow(address: SocialMedia)-> ViewRow<SocialMediaViewFile> {

let viewRow = ViewRow<SocialMediaViewFile>() { (row) in

    row.tag = UUID.init().uuidString
    }
    .cellSetup { (cell, row) in
        //  Construct the view
        let bundle = Bundle.main
        let nib = UINib(nibName: "SocialMediaView", bundle: bundle)

        cell.view = nib.instantiate(withOwner: self, options: nil)[0] as? SocialMediaViewFile
        cell.view?.backgroundColor = cell.backgroundColor
        cell.height =  { 50 }
        print("LINK \(address.facebook?[0] ?? "")")

        cell.view?.iconOne.tag = 90090

        //self.itemDetails.activeURL = address

        let openFace = UITapGestureRecognizer(target: self, action: #selector(QuickItemDetailVC.openFace))
        let openT = UITapGestureRecognizer(target: self, action: #selector(QuickItemDetailVC.openTwit))
        let you = UITapGestureRecognizer(target: self, action: #selector(QuickItemDetailVC.openYouYub))

         cell.view?.iconOne.addGestureRecognizer(openFace)

         cell.view?.iconTwo.addGestureRecognizer(openT)
         cell.view?.iconThree.addGestureRecognizer(you)



        cell.frame.insetBy(dx: 5.0, dy: 5.0)
        cell.selectionStyle = .none

    }.onCellSelection() {cell,row in

     //example   
    //print(iconTwo was clicked)


}


return viewRow
}

标签: iosswiftuitablevieweureka-forms

解决方案


使用UITapGestureRecogniser(or UIButton) 将是更好的方法。这些类用于此类任务。

如果您仍想使用不同的方法,请将方法添加到您的单元子类(替换imageView1, imageView2, imageView3为您自己的属性)

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
  guard let touch = touches.first else { return }
  let point = touch.location(in: view)
  if imageView1.frame.containsPoint(point) {
    // code for 1st image view
  } else if imageView2.frame.containsPoint(point) {
    // code for 2nd image view
  } else if imageView3.frame.containsPoint(point) {
    // code for 3rd image view
  }
}

文件:


推荐阅读