【问题标题】:How to segue when a button is held in a TableView cell如何在 TableView 单元格中按住按钮时进行 segue
【发布时间】:2020-08-25 12:48:09
【问题描述】:

我有一个非常复杂的问题,按钮已经有一个作为@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)
    }

【问题讨论】:

    标签: ios swift uitableview button segue


    【解决方案1】:

    您可以在情节提要中从表格所在的 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 替换为您在情节提要中指定的标识符。

    Apple Developer Documentation

    【讨论】:

    猜你喜欢
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 2013-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-19
    相关资源
    最近更新 更多