1

I'm using accessoryView, not button. This means I can't use the "accessoryButtonTappedForRowWithIndexPath" method. Itried to add a tap gesture recognizer to my view, but it won't work for the following reasons:

  • I need the indexPath of the selected accessoryView, so I can't call a generic "cellAccessoryTapped()" function since it wouldn't have the index path.

  • I can't pass in any parameters into the selector as to pass in my index path.

Here is the code for my accessoryView:

 let ellipsesImageView = UIImageView(image: UIImage(named: "ellipses-nav-bar-icon"))
        cell.accessoryView = ellipsesImageView
        cell.accessoryView?.tintColor = Theme.Color.Primary.primaryBlack
        cell.accessoryView?.userInteractionEnabled = true

        let cellTapGestureRecogznier = UITapGestureRecognizer(target: self, action: #selector(self.tableView(_:accessoryButtonTappedForRowWithIndexPath:)))
        cell.accessoryView?.addGestureRecognizer(cellTapGestureRecogznier)

The app crashes when I tap on a cell, and doesn't go into the table view method at all, so I do not think I'm permitted to use it.

How would I go about finding the index path of the cell given the selected accessory view?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Faisal Syed
  • 921
  • 1
  • 11
  • 25
  • Why are you trying to call the `accessoryButtonTappedForRow` method when your custom view is tapped? Setup your own method to be called that has the correct parameters for a tap gesture target selector. – rmaddy Nov 07 '16 at 21:32
  • I thought you weren't allowed to have parameters in a selector? – Faisal Syed Nov 07 '16 at 21:34
  • You have two in the selector your are mistakenly trying to use. – rmaddy Nov 07 '16 at 21:35
  • so assuming I create the method "handleAccessoryViewTapped(indexPath:NSIndexPath)", how would I get the proper index path for the cell in which the accessory view was tapped? – Faisal Syed Nov 07 '16 at 21:37
  • If you have only one section, you can set `tag` property of `accessoryView` to pass `row` index into your callback method. You can access it then on `sender` parameter. – alexburtnik Nov 07 '16 at 21:44
  • I do only have one section. That's interesting...where would the callback method go though? – Faisal Syed Nov 07 '16 at 21:53
  • No, the tap gesture selector can only have one specific parameter and that is the tap gesture. – rmaddy Nov 07 '16 at 22:21

0 Answers0