2
votes

A segue in my app is being called multiple times, which is causing the view to continuously "load" until the app stops calling the segue function. It does this about 4 times until it's finished. After placing breakpoints in the code I noticed that the app is bouncing between these two functions:

if success {
    self.performSegueWithIdentifier("startGame", sender: "user")
}

That is the action that triggers the segue (the user swipes something). It then goes to the next breakpoint:

if (segue.identifier == "startGame") {
    let destinationNavigationController = segue.destinationViewController as! GameViewController
     destinationNavigationController.user = self.users[self.currentUser]
 }

The app goes back and forth between the two sections about 4 times. When I created the segue in my storyboard I made sure to wire the segue from the view controller itself (not a table/UI view) to the destination view.

What else can I do to fix this?

Thanks!enter image description here

1

1 Answers

0
votes
  1. In storyboard, create a segue by holding control and dragging from the yellow icon of the 1st view controller to the 2nd view controller.
  2. Give it an id, and the kind should be push if they are embedded in a navigation controller.
  3. In your 1st view controller class:

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "startGame" {
        let viewController = segue.destinationViewController as! GameViewController
        // this next view controller should have property that will store passed value
        viewController.user = self.users[self.currentUser]
    }
    

    }

  4. When you want to move to the next view controller:

    performSegueWithIdentifier("startGame", sender: self)