Save view state on reboot

I am developing an iPad application, which is a sequence of user instructions to simulate a real-life test, with the ability to make changes to each view if the components have failed (indicating problems that need to be solved).

The problem I am facing is that the default behavior in the default views is that as you move forward in the hierarchy, it keeps the state of each view, but if I move back and then move forward again, it will have reset screen.

I would like each view to maintain its state regardless of how the user leaves this screen, so that they can be sure that their work is saved, even if they need to return to the previous step.

Is there any way to do this? Or do I need to fundamentally review my design?

+1
source share
1 answer

You need model objects for your views. They can be as simple as dictionaries, or be used as a custom class for each view.

Each view controller must update its associated model with the changes made through its interface before the view goes beyond the screen. When it reappears, VC will update the display with information from the model.

Cocoa Model-View-Controller (. : Cocoa ); , , .

. , . xField UITextField s.

// When the view is taken off screen
- (void) viewWillDisappear {

    // Assume that when created, view controller is given a pointer 
    // to the relevant model object (probably by the previous view
    // controller)
    [model setNameOfHorse:[[self horseNameField] text]];
    NSUInteger newBetValue;
    newBetValue = [[dollarValueFormatter 
                        numberFromString:[[self betField] text]] 
                    unsignedIntegerValue];
    [model setBet:newBetValue];
    [model setNote:[[self noteField] text];
}
+1

All Articles