0

I'm having trouble with Unwind Segue. I have 3 ViewControllers and they all under the class called ViewController.swift. I'm trying to get the last ViewController which is the 3rd to to go the beginning ViewController with just a tap of a button but I can't seem to get it. I tried to research before submitting this question but couldn't find it. If there is more information you need let me know.

vacawama
  • 150,663
  • 30
  • 266
  • 294
jas bath
  • 63
  • 2
  • 9

1 Answers1

0

You have VC1 -> VC2 -> VC3 and want to unwind from VC3 directly to VC1. In order to do this, you need an @IBAction defined in VC1 that isn't defined in VC2. That is currently not possible since all of your ViewControllers are using the same class definition in ViewController.swift.

One way to resolve this without duplicating all of the code in ViewController.swift is to subclass ViewController and add just the function that is unique to VC1. Then in the Storyboard, select the first ViewController and in the Identity Inspector set the Custom Class to MainViewController.

class MainViewController: ViewController {
    @IBAction func returnToMain(segue: UIStoryboardSegue) {
        print("back in the MainViewController")
    }
}

Then, when you set up your unwind segue, control-drag from your button to the Exit icon at the top of your 3rd ViewController and select the returnToMain action from the pop-up.

vacawama
  • 150,663
  • 30
  • 266
  • 294
  • Sorry Im new, how would I subclass VC1? – jas bath Jan 05 '16 at 06:11
  • Each viewController should have its own associated class. See this question about how to add a new class for the viewController. http://stackoverflow.com/q/26962713/1630618. The answer above assumes that there is a lot in common between your viewControllers and you don't want to duplicate the entire viewController.swift file. The code above shows how to subclass another viewController and add just the extra function you need as the "landing spot" for returning from another viewController. – vacawama Jan 05 '16 at 13:56
  • Thanks a lot, Im beginning to understand more on the UnwindSegue stuff. – jas bath Jan 05 '16 at 22:33
  • I have another question. Im making something that is longer than 10,000 height for a scrollView. I've made it 10,000 but when I go beyond 10,000 it will give an error, is there a way to go beyond 10,000? I have used many apps that go beyond the number 10,000 but when I try to create something beyond 10,000 it would give me an error saying "Interface Builder does not support UIView sizes larger than 10,000 by 10,000." This would help me a lot of it would be possible, but I have seen a lot of apps that have a scrollView longer than 10,000. – jas bath Jan 05 '16 at 22:40
  • You should ask a new question since this is totally unrelated to unwind segues. If the answer to this questioned solved your problem, please accept it by clicking on the checkmark on the left to turn it green. Thanks. – vacawama Jan 05 '16 at 22:45
  • I would but it won't let me. I have to wait 5 days :( – jas bath Jan 06 '16 at 02:45