Answer the question
In order to leave comments, you need to log in
How to save the state of a ViewController after switching to another ViewController?
Swift.
There are 2 ViewControllers.
I make the transition from the first to the second through the presentViewController, while in the first property - the value was written before the transition. Then I go back (I pass the value from the second ViewController to the first one via segue, and for some reason the first one is empty again. The previously written property value is set to zero.
How can I make the ViewController no longer initialize after initialization and save the state during transitions?
Thank you.
Answer the question
In order to leave comments, you need to log in
Well, I initially see the wrong approach here. The VC from which you switched was unloaded from memory and its empty object remained, therefore you will not be able to simply write a value to property, since it no longer exists. There are several methods to solve.
1. You can use some static class that is always in memory, which will check if something has changed. If it has changed, then overwrite the property, otherwise do nothing.
2. Transferring information on the navigation stack to the previous controller.
3. Using the essence of any object as a keeper of information, which is also permanently or currently in memory.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question