Unwind segue - return multiple views

Suppose I have 3 ViewControllers - A, B and C. A shows B, B shows C. Then I want to go back to A without going through (visually) B (for example, the home button). My problem now is that when I unwind A, B is displayed for a short period of time (viewWillAppear methods are called, etc.). How can i solve this?

Note 1. The above example is very simplified compared to my real navigation application tree, and for me, using the NavigationController as a container for all A, B and C is not possible (or at least not desirable). Few of the reasons are in the middle of the transition, there are complex segues and various user changes (almost all animated transitions are completely different) in all views.

Note2: I found some pseudo-solution with defining custom segue and using it as Custom Unwind Segue. This is undesirable because I want to use my already done transitional animators.

Any help is appreciated.

+6
source share
1 answer

Please note that this is a corrected answer - in response to the first comment below.

I have a possible solution that seems to work. But this may not be acceptable. I am not sure and offer it only for consideration.

The 3 view managers are configured as described in the question (the second is red so I can see if this is visible during unwinding).

enter image description here

U-roll is created in the third view controller (C) by dragging and dropping in Exit. Before this, the necessary actions must be added to the first and second view controllers.

enter image description here

enter image description here

Below is the code for 3 controllers. My fix - I use the global logical name unwindCheck as a flag that sets true before disconnecting, but false otherwise. If this is true , then self.view.hidden = true in viewWillAppear for the second view controller. those. hidden during unwinding.

Note that I also added a second button on the third view controller - it calls the same segue spread - whose identifier property is set to "UnwindToFirstSegue" . The second button is not a necessary part of this possible solution.

 class FirstViewController: UIViewController { @IBAction func unwindToFirstViewController(segue: UIStoryboardSegue) { } override func viewDidLayoutSubviews() { unwindCheck = false } } class SecondViewController: UIViewController { override func viewWillAppear(animated: Bool) { super.viewWillAppear(animated) if unwindCheck == true { self.view.hidden = true } } @IBAction func unwindToSecondViewController(segue: UIStoryboardSegue) { } } class ThirdViewController: UIViewController { @IBAction func backToA(sender: AnyObject) { performSegueWithIdentifier("UnwindToFirstSegue", sender: self) } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if let identifier = segue.identifier{ switch identifier { case "UnwindToFirstSegue": unwindCheck = true default: break } } } } 

The unwind identifier can be set by selecting it in the document structure, and then go to the attribute inspector.

+1
source

Source: https://habr.com/ru/post/988454/


All Articles