In general, how to use segue clear;

Here for example there is such a piece of code


 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == StoryBoard.ShowImageSegue { if let ivc = segue.destination.contentViewController as? ImageViewController { let imageName = (sender as? UIButton)?.currentTitle ivc.imageURL = DemoUrl.NASAImageNamed(imageName: imageName) ivc.title = imageName } } } 

There is a split view button in it, I click on the button to open the next view controller .

So at what point segue this segue work in this function?

Here in android let's say start Activity() activity start Activity() is understandable and how this line of code will be executed will be sent a request to open the desired activity ...

And in iOS there is no such line and it is not clear at what point this request to open the desired screen flies

    1 answer 1

    This does not work, here is the preparation for the transition.

    segue is a transition. Transition from one controller to another.

    The sequence of calls to seque methods:

    • initWithIdentifier:source:destination: (initialization)
    • prepareForSegue:sender: (preparation, for us the most "popular" method)
    • perform (here it works)

    Well, what about when it works - when the conditions are fulfilled, then it works. Pressed the button, prepared and worked.

    If you compare with android, then there is no such close. Analog of startActivity() will be present(:animated:completion:)

    • So if I understand correctly, the transition includes 3 methods; we override only one prepareForSegue:sender: but the transition itself is prepareForSegue:sender: in perform , but we do not override it, right? - Aleksey Timoshchenko
    • @AlekseyTimoshchenko from the main yes. In the "life cycle" segue at the very beginning there is also the initialization of the controller to which the transition and deinitialization of seque should take place at the end. - VAndrJ
    • At first perform triggers which initializes segue , and then prepare: Documentation performSegue: Initiates the segue with the specified identifier from the current view controller's storyboard file. This is when segue manually called. And if a segue in a storyboard attached to some kind of event , then everything happens a little differently. - Fahri Azimov
    • @FahriAzimov do not confuse the perform class UIStoryboardSegue , which performs the transition and performSegue(withIdentifier:sender:) class UIViewController . And the life cycle is the same for the segue , that in the code through performSegue perform that in the interface of the builder on the button which hang. - VAndrJ