在 TableView 中检测 UIGestureRecognizer 的来源单元

Detect provenance cell of an UIGestureRecognizer in a TableView

我有一个动态 TableView,在每个单元格中都有一个 MKMapView。我需要这样,当用户点击地图(不包括地图)时,应用会显示一个带有展开地图的新控制器。

我开始在地图上放置一个 UITapGestureRecognizer,但我发现,从 iOS 9 起它不起作用,所以我按照这个 并且它工作正常;麻烦是我找不到一种方法来检测 UITapGestureRecognizer 来自哪个单元格。

我尝试为每个 UITapGestureRecognizer 分配一个标签,但似乎不可能,那我该怎么办?

如果您使用的是您喜欢的解决方案,则可以从在步骤 4 中传递给函数的 UITapGestureRecognizer 中确定单元格:

func imgFaild_Click(sender: UITapGestureRecognizer) {
   let location = sender.locationInView(self.tableView)
   let indexPath = self.tableView.indexPathForRowAtPoint(location)
   //do something with the indexPath
 }