How do I do something after the session ends?

I am using a segue in a storyboard to present a modal view controller. Instead of segue, I can use presentViewController: animated: completion to do something in the completion block. But now I don't know when the segue will end and where to put my exit codes
Here are the codes I used before:

presentViewController:modalViewController animated:YES completion:^{

    modalViewController.items = items;
    [modalViewController showItem:itemdIndex];
}];

      

I need to call the modalViewController method from outside.

+3


source to share


2 answers


you need to subclass UIStoryboardSegue

and implement the run method in it. After that in the storyboard, you will set the segue class to the one you just created.

Or, you can put the code in methods ViewDidLoad

or the ViewWillAppear

view that you are viewing.



Your best bet is to go ViewDidLoad

this way, your code will only be executed once when the view is loaded first.

+2


source


Place them in the viewWillAppear:

view controller you navigate to.



Note. If you add view controllers to the stack (inside a for example UINavigationController

), viewWillAppear:

will be called every time the view controller is redirected (even if you return to it from another view controller). If you want your code to only run once (when it was originally loaded) then put it in instead viewDidLoad

.

+1


source







All Articles