D
D
dimib2014-10-01 22:33:07
iOS
dimib, 2014-10-01 22:33:07

Why are all objects removed when leaving the ViewController?

Good day.
I have two ViewControllers. In the first I have a button with which I create an object in the second and go to it. In the second ViewController, I can change the position of objects. But as soon as I return to the first and go back to the second, all the objects that I changed are deleted. That is, their changes are not saved in any way and every time you log in, everything is all over again. How to fix it? Is it really necessary to create arrays of objects and their positions and create all the objects in the right places again with each new entry?
And another question: I learned how to pass variables between classes, and thanks to this I create an object in the second View by pressing a button in the first one. But in this case, the object will be created only when I go to the second window. How to make the object created immediately?
I do it like this:

View1.h
...
-(IBAction)AddLabel:(id)sender {
    _AddLabel = YES;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    FullViewController *destViewController = segue.destinationViewController;
    destViewController.AddLabel = _AddLabel;
}
...



View2.h
...
- (void)viewDidLoad {
    [super viewDidLoad];
    if (_AddLabel==YES) {[self CreateLabel];}
}
...

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Morozov, 2014-10-02
@morozovdenis

Because the second ViewController is removed from memory. If you need to remember the state changed by the user, then save it (the state) to a file and when opening the second ViewController, read the file and restore the state.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question