4

www.dropbox.com/s/jrzrst5qtfq6op2/Screenshot%202015-03-20%2022.27.42.png?dl=0

This highlighted line is where should popToRoot proceed, after a successful registration it should redirect to Root View Controller. For some reason it's not working for me, literally nothing happens, not even error.

I tried with

self.navigationController?.popToRootViewControllerAnimated(true)
Rob
  • 415,655
  • 72
  • 787
  • 1,044
murga108
  • 61
  • 6

1 Answers1

3

You don't appear to be using navigation controller at all, so I'd wager that self.navigationController is nil.

You could use an unwind segue. So in your root view controller, add a method like so:

@IBAction func unwindToRoot(segue: UIStoryboardSegue) {
    print("successfully unwound")
}

Then in your scoreboard scene from which you want to unwind, you can control-drag from the button to the "exit outlet":

enter image description here

When you let go, you can pick the unwind action:

enter image description here

This achieves the "pop to root" sort of functionality, but is not contingent upon using navigation controller.


If you want to perform this unwind programmatically, rather than doing the segue from the button to the exit outlet, do it from the view controller icon to the exit outlet:

enter image description here

Then, select the segue in the document outline and give this segue a unique storyboard id:

enter image description here

Then you can programmatically perform the segue, using the same identifier string:

performSegueWithIdentifier("UnwindToRoot", sender: self)
Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • Thank you very much for your response. I tried but it crashes for some reason. But let's get to that later. Is this way working with my if statement. It's basically register form with some error checkings(If fields are empty, and Parse back-end errors ). If error != nil { //Error } else { //Unwind segue? } Can it work like this ? – murga108 Mar 20 '15 at 22:32
  • You can create a "manual segue" by control-dragging from the view controller icon to the exit icon; then give that segue a unique identifier and then you can perform it programmatically with `performSegueWithIdentifier`. See expanded answer. – Rob Mar 20 '15 at 22:40