1
votes

I have an unwind segue question.

I have two View Controller, "main" and "about". I want to achieve the following simple actions:

  1. When a button (A) on "main" is clicked, the "about" view is showed.
  2. When a button (B) on "about" is clicked, the "about" view is gone and the "main" view is returned.

I didn't use any navigation controller. What I did is as follows:

  1. Create a "Show" segue from button (A) to "about".
  2. Customize the UIViewController of "about" view controller and create an IBAction func unwind(s: UIStoryboardSegue). Only one line of code is in it: print("unwind")
  3. Control-drag from button (B) to "exit" button on "about" view controller and link up the unwind segue to the unwind func.

However, when I click button (B) on "about" view, the print is not triggered, nor the "about" view unwinds.

I have no idea what's going on here and would like some help. I am on xcode 7, using swift 2 under iOS 9.

Thank you.

1

1 Answers

4
votes

I have figured it out. The unwind func should be put in "main" view controller rather than the "about" view controller. Then when you control-drag the button (B) to exit on "about" view controller, IB can also detect the unwind func from "main" view controller. This is really weird design to me but I guess that's because I am new to iOS development.