Search code examples
iosswiftsegue

Programmatically Unwind Segue?


I have 2 ViewController, let's say Feed and Login. Initial page is the Feed and if not authenticated, user is getting directed to Login page. After filling the form, on successful login, I am trying to unwind back to Feed page.

In FeedVC, I added:

@IBAction func unwindToFeed(segue: UIStoryboardSegue){

}

In LoginVC, on login-button press

@IBAction func loginButton(sender: AnyObject) {
  func authenticatedUser (...) {

    if error != nil {
          // error handling
    } else {
         // success

        NSOperationQueue.mainQueue().addOperationWithBlock({
           self.performSegueWithIdentifier("unwindToFeed", sender: self)
        })
    }
  } 
}

However, on success, it doesn't get unwind-ed, and I'm getting an error

Terminating app due to uncaught exception 'NSInvalidArgumentException', > reason: 'Receiver ( 0x7fd789a2cab0>) has no segue with identifier 'unwindToFeed''

In Storyboard, in LoginVC, I also tried to ctrl+dragging from Yellow (ViewController) to Exit, at the top. However as soon as I do that, I receive "Segues initiated directly from view controllers must have an identifier" and in Login View Controller Scene it shows Unwind segue to 'Exit'.

What am I doing wrong?


Solution

  • Found my answer. I didn't name the segue as it said.

    Solution: Click on "Unwind segue to 'Exit'", on right panel, 'Storyboard Unwind Segue', you will see.