ios - 无法从 UITableViewCell 显示弹出窗口

标签 ios iphone xcode swift3

<分区>

我有一个表格 View ,单击标签时我想使用弹出窗口方法显示 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]: unrecognized selector sent to instance 0x7fdc1867ee90 2017-05-23 17:36:23.871 InvoiceMaster[71236:14670269] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITapGestureRecognizer tag]: unrecognized

最佳答案

jsut change this method like below

 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!)  
 }

关于ios - 无法从 UITableViewCell 显示弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44134398/

上一篇:iOS 检测应用程序已关闭

下一篇:ios - 在 Objective c 的自定义 UITable View 中从服务中获取数据

相关文章:

ios - 从服务器监听 iCal 事件变化

iphone - 如何从 uiimageview op uibutton 中删除图像

iphone - 在 objective-c 中解析文本文件

ios - 如何将单个 tileset 图像导入 xCode(Sprite Kit)?

xcode - Xcode 6 GM无法在OS X Yosemite上启动

ios - UIButton 如何同时监听对其他按钮的更改、对 UILabel 文本的更改以及对 UITextView 的更改

ios - 有没有办法强制ios系统清除部分(或全部)应用程序的缓存?

ios - 应用程序终止时无法处理本地通知

ios - 如果在 xcode 中布局高度比设备高度长怎么办?

javascript - IOS WebRTC js 黑屏