【发布时间】:2020-04-27 15:55:46
【问题描述】:
好的,这个可能有点难以说明,但问题是:我尝试在 tableView 单元格上附加一个长按手势识别器,并将其链接到 Viewcontroller 中。但是,手势不适用于表格中的每个单元格 - 只有 1 个。并且它作用于变化的 1 个单元格(有时是第一个,有时是第二个,等等 - 取决于实际有多少单元格有数据)。如果有人能指出我正确的方向,将不胜感激。
以下是处理手势的代码。谢谢!
if recognizer.state == .changed
{
let alertController = UIAlertController(title: nil, message:
"Open Product in Safari", preferredStyle: .alert)
let indexPath = tableView.indexPathForSelectedRow
let itemSku = self.itemArray[indexPath?.row ?? 0].sku
alertController.addAction(UIAlertAction(title: "Go to Safari", style: .default,handler: { action in
UIApplication.shared.open(URL(string: "\(itemURL)\(itemSku ?? "")") ?? URL(string: "")!, options: [:]) { _ in
print("Link opened")
}
}))
present(alertController, animated: true, completion: nil)
}
}
【问题讨论】:
标签: ios swift xcode tableview cell