ios - 如何在 TableView 单元格中按住按钮时进行 segue
问题描述
我有一个非常复杂的问题,按钮已经有一个作为@objc 函数的点击动作。我可能必须为 cellForRow 函数实现代码,但它如何仅在这些函数起作用时调用?
@objc func longPress(gesture: UILongPressGestureRecognizer) {
if gesture.state == UIGestureRecognizer.State.began {
print("Long Press")
//Was trying to figure out how to add segue call here
}
}
func addLongPressGesture(){
let longPress = UILongPressGestureRecognizer(target: self, action: #selector(longPress(gesture:)))
longPress.minimumPressDuration = 0.75
self.expandButton.addGestureRecognizer(longPress)
}
解决方案
您可以在情节提要中从表格所在的 ViewController 中添加一个 segue 到您想要转到的 View 中。然后给它一个标识符并调用func performSegue(withIdentifier identifier: String, sender: Any?)
@objc func longPress(gesture: UILongPressGestureRecognizer) {
if gesture.state == UIGestureRecognizer.State.began {
print("Long Press")
performSegue(withIdentifier: String "showFromLongPress", sender: nil)
}
}
这里当然用showFromLongPress
你在情节提要中指定的标识符替换标识符。
推荐阅读
- paypal - 多次加载 Paypal 结帐按钮
- mysql - 使用 union all 时操作“concat”的排序规则的非法混合
- android - 如果我发布的库使用 AndroidX 但使用它的应用程序不是,有什么问题吗?
- hyperledger-fabric - 当网络出现故障时,所有 Hyperledger Fabric (v 1.4.2) 对等点都会崩溃
- sql - 根据每个项目的最新交易日期选择数据
- powerbi - 如何将 Excel 转换为 DAX 公式?
- c# - 使用正则表达式分组结构匹配部分字符串
- spring-boot - MockMvc 保持为空
- javascript - 如何在 sequelize findAll 中包含特定关联?
- python - 我不知道为什么会出现“TypeError: '<' 在 'str' 和 'int' 的实例之间不支持”错误