1
votes

I had a swipe gesture in a view controller working working perfectly and reporting to the output. Something simple like this:

 @IBAction func leftSwipe(sender: UISwipeGestureRecognizer) {
    println("ok") 
}

But then I took that same gesture recognizer and attached a segue to it that would cause it to modally switch view controllers when the swipe was detected. I did that all in storyboard with a simple control click, drag the gesture recognizer to the view controller I want to change to, and select one of the segue animation options. It worked as expected and when I swipe the view controller changes to another one, but... the IBAction stopped working completely, I even used a breakpoint and it never breaks there. Do triggered segues cancel out other sent actions normally? I could always add another gesture recognizer but is this behavior normal?

Small update: Adding a new gesture recognizer worked and it can be recognized with an IBAction but now the previous gesture does not work and the view controller does not change.

SOLUTION: Thanks to Firas for pointing me in the right direction, I found the method prepareForSegue explained by apple here I implemented the method in the view controller that is sending the segue like this:

 override func  prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "yourSegueID" {
        println("segue happened, so the gesture did too!")
    }
}

Maybe there could be problems with associating the segue with the gesture like that but for my implementation I can't really see anything that could happen.

1

1 Answers

0
votes

What you can do is take the segue from the viewController not from the gestureRecognizer and give that segue an identifier let's say segueIdentifier, then on your action call self.performeSegueWithIdentifier... or do something else.

Whenever you create a segue directly from a view or gesture recognizer the action on that view/gestureRecognizer will no execute