0

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)
    }
Douglas
  • 65
  • 10

1 Answers1

1

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

Ix76
  • 86
  • 7
  • That doesn't work because the cell doesn't contain that function, also you can't call it because it would try to perform the function of the ViewController itself – Douglas May 09 '20 at 23:53
  • Oh ok, so what about that: [Performing a segue from a button within a custom UITableViewCell](https://stackoverflow.com/questions/26880526/performing-a-segue-from-a-button-within-a-custom-uitableviewcell) – Ix76 May 10 '20 at 10:28