0

I'm a new developer and have a paperclip image in the custom cell of my table view. When I click the paperclip, it triggers a segue to open another viewController that is supposed to provide data relative to the row where the paperclip image is located.

I have a protocol set up to manage the navigation and the segues which is all working. The problem I have is that when I select the image, it does not go into the DidSelectRowAt method and consequently I'm not able to capture the relevant indexPath of the row that is selected.

Can someone point me in the direction of how to do that?

  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
    let cell = tableView.dequeueReusableCell(withIdentifier: "HealthLogCell", for: indexPath) as! LogTableViewCell
    
    self.healthLog = healthLogs[indexPath.row]
    cell.delegate = self
   
 }




Protocol OpenLogDocumentsProtocol {
  func openLogDocuments() 
}

class LogTableViewCell: UITableViewCell {

var delegate: OpenLogDocumentsProtocol?

@IBOutlet weak var labelComment: UILabel!
@IBOutlet weak var labelDate: UILabel!

//THIS IS THE IMAGE THAT INTERACTS.
@IBOutlet weak var imagePaperclip: UIImageView!

var healthLog: HealthLog1?
   

override func awakeFromNib() {
    super.awakeFromNib()
    


    imagePaperclip.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(imageSelected)))
    
    imagePaperclip.isUserInteractionEnabled = true
    
}



@objc func imageSelected() {
    
    //print (superclass?.healthLog)
    delegate?.openLogDocuments()
 }

}
Himanshu Patel
  • 1,015
  • 8
  • 26
Linus Bicker
  • 129
  • 1
  • 8

1 Answers1

0

Custom Cell declare

protocol purchaseOrderCellDelegate: class  {
  func onPressOpinionSurvey(index: Int)
}
class purchaseOrderCell: UITableViewCell {

//MARK: - Variable Declaration
weak var delegate: purchaseOrderCellDelegate?

//MARK: - IBOutlet
@IBOutlet weak var imgIteam:UIImageView!
@IBOutlet weak var btnProductOpinion:UIButton!

//MARK: - LifeCycle
override func awakeFromNib() {
    super.awakeFromNib()
    // Initialization code
    
}
override func layoutSubviews() {
    super.layoutSubviews()
}
//MARK: - IBAction
@IBAction func onPressOpinionSurvey(_ sender:UIButton){
    delegate?.onPressOpinionSurvey(index: sender.tag)
 }

}

Please declare "purchaseOrderCellDelegate" on UIViewController

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! purchaseOrderCell
    let dict = self.viewModel.purchaseRecordModel.value!.results[indexPath.row]
    cell.delegate = self
    cell.btnProductOpinion.tag = indexPath.row        
    return cell
}

func onPressOpinionSurvey(index: Int) {
    print(index)
    self.selectedIndex = index
}
Himanshu Patel
  • 1,015
  • 8
  • 26