Hello. In diagram 3 of the screen:

  1. Data you need to filter
  2. Filtered data
  3. Filtering settings

Screen 3 is opened by clicking on the "Filter settings" button via Modal Segue (screens 1 and 2).
Screen 2 opens when you click the "Filtered" button (screen 1) via Show Segue.

When you click on "Cancel" (screen 3), the dismiss function is called, closing the modal window, the screen from which the "Filter Settings" button was pressed is returned, the navigation between
1 -> 2 and 2 -> 1 works as it should.

However, I ran into a problem, how to correctly open the screen 2 when pressing the "GO TO FILTERED" button from screen 3, so that the parameters for filtering were transferred to the control class of screen 2 and the navigation between 2 -> 1 did not break? Tried through different Segue, but navigation then does not work.

modal segue problem

  • I will offer to return to screen 1 without animation, and from there to go to 2 (I assume that the model is stored somewhere separately, and has no relation to the transition). Either make the screen 3 part of the stack (such as screen 1.5) and then, if necessary, go from 1 to 2 just add 1.5 and 2 to the stack together - Max Mikheyenko
  • or when you click go to filtered to watch who shows the modal screen, and replace it with screen 2, and after that do dismiss - Max Mikheyenko
  • @MaxMikheyenko, thanks for the comment, I considered the option of going to 1 screen, and then to 2 ... but I thought that there should be a more elegant solution, because Just started to master ios. About the use of the stack, did not quite understand. Do you suggest removing screen 3 and making it part of screen 1? Here is an option to watch who shows the screen I like more. Can you give a simple code example how can this be implemented? or at least what functions to use? Who shows this Presenter? How can I change it? - Victor

1 answer 1

As a result, I solved this problem using Unwind Segue. For this, I added a function to screen classes 1 and 2

@IBAction func prepareForUnwind(segue: UIStoryboardSegue){ } 

On screen 3, I tied the "GO TO FILTERED" button to prepareForUnwind via Unwind Segue. This method allows you to automatically determine from which screen (1 or 2) screen 3 was opened. Then, in screen class 1, implemented the code to go to screen 2 immediately after exiting screen 3.

 var fromFilterSettings = false @IBAction func prepareForUnwind(segue: UIStoryboardSegue){ fromFilterSettings = true } override func viewDidAppear(_ animated: Bool) { if fromFilterSettings { performSegue(withIdentifier: "showFiltered", sender: self) fromFilterSettings = false } }