我有一个tableview,点击一个标签,我想使用popover方法从storyboard中显示一个UIViewController。我在点按识别器选择器中有以下代码
func setupItemNameTapRecognizer(_ label:UILabel) {
label.isUserInteractionEnabled = true
let tapRecog = UITapGestureRecognizer(target: self, action: #selector(self.actionItemNameTap(_:)))
label.addGestureRecognizer(tapRecog)
}
func actionItemNameTap(_ sender:UIView) {
print("item tap")
let indexPath = IndexPath(row: sender.tag, section: 0)
let cell = tableView.cellForRow(at:indexPath )
self.showPopOverBox(cell: cell!)
}
并在CellForRowAt方法中使用以下代码
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemContentCell", for: indexPath) as! ItemContentCell
setupItemNameTapRecognizer(cell.itemName)
cell.itemName.tag = indexPath.row
return cell
每当我点击标签时,我都会抛出以下错误,而不会发生什么错误
[UITapGestureRecognizer tag]:无法识别的选择器发送到实例0x7fdc1867ee90 2017-05-23 17:36:23.871 InvoiceMaster [71236:14670269] ***由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:' - [UITapGestureRecognizer标记]:无法识别
答案 0 :(得分:1)
jsut更改此方法,如下所示
func actionItemNameTap(_ sender: UITapGestureRecognizer) {
// let view = sender.view;
// print("\(view?.tag)")
print("item tap")
let indexPath = IndexPath(row: (sender.view?.tag)!, section: 0)
let cell = tableView.cellForRow(at:indexPath )
self.showPopOverBox(cell: cell!)
}