Douglas
Douglas

Reputation: 65

How to segue when a button is held in a TableView cell

I have a pretty complex problem where the button already has a tap action as an @objc function. I likely have to implement code to the cellForRow function but how would it only call when these functions are at play?

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

Upvotes: 0

Views: 196

Answers (1)

Ix76
Ix76

Reputation: 86

you could add a segue in your storyboard from the ViewController the table is in to the View you want to go to. Then give it an identifier and call 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)
        }
    }

Here of course replace the identifier showFromLongPress with the identifier you specified in the storyboard.

Apple Developer Documentation

Upvotes: 1

Related Questions