2

I want to create an app in Xcode 8.0 that lets the user press a bar button item in the navigation bar. Once this button has been clicked an unwind segue will take place whilst also printing, "helloWorld" to the output section at the bottom of Xcode. I have successfully created an unwind segue using:

@IBAction func unwindToViewController (sender: UIStoryboardSegue){

    }

I then linked this to the bar button item on the navigation bar so that when I tap the bar button item on the navigation bar the view disappears downwards.

I am trying to simply print("helloWorld") onto the output section at the bottom of Xcode when I press the done button but nothing appears on the output section. So far I have:

@IBAction func add(_ sender: AnyObject) {



    print("helloWorld")

}

in the View Controller Swift File for that View Controller.

D. Murphy
  • 67
  • 3
  • 11

3 Answers3

2

For unwind We need to remember only two points

1) We need to put below method into Destination ViewController.It is a place where we want to navigate to. Here method name can be different but arguments matter a lot.

 @IBAction func unwindToDestinationViewController (sender: UIStoryboardSegue){

 } 

2) Go to the Source viewController from where you want to go back. Now click on unWind button on top right and Control-Click and set outlet to the Back button(Example)

1

Kindly check this post on stack overflow. This is a duplicate of below post.

You can find the answer in the given below link.

https://stackoverflow.com/a/39916477/2894335

This Blog gives a very nice introduction to unwind segues. article link here.

Karthik Kumar
  • 1,375
  • 1
  • 12
  • 29
0

Try the following tutorial will fix your problem and help you to understand more about how to perform unwind segue...

https://www.andrewcbancroft.com/2015/12/18/working-with-unwind-segues-programmatically-in-swift/#identifier

http://ashishkakkad.com/tag/uistoryboardsegue/

Hope this helps...

Joe
  • 8,868
  • 8
  • 37
  • 59