views:

295

answers:

2

Hi,

We are implementing one web based application in iPhone. if i answered the incoming phone call my application is relaunching once again instead of resume the application to the state where it last the focus.

we are implementing stack of views. I.e i am maintaining views in a stack manner and each view has the information like images and text information, if i am in 3rd or 4th view, if i answered the incoming phone call my application is relaunching and it is showing 1st view only.

Please tell me how to resume to the 4th view level.

A: 

See Apple's DrillDownSave sample - it demonstrates how to do that.

Vladimir
A: 

Unfortunately the iPhone doesn't do very much to help you here. I can't guarantee that this will be useful for you but this is how I do it.

In my app I have the following protocol:

@protocol SaveState

    - (NSData*) saveState;
    - (id) initWithSaveState:(NSData*)data;

@end

Any UIViewController that I need to be able to save its state implements it.

In applicationWillTerminate: I have the following code:

for (UIViewController* vc in self.navigationController.viewControllers) {
    if ([vc conformsToProtocol:@protocol(SaveState)]) {
        NSArray* state = [NSArray arrayWithObjects:NSStringFromClass([vc class]), [(UIViewController<SaveState>*)vc saveState], nil];
        [vcList addObject:state];
    }
}

I then save vcList to the NSUserDefaults. To restore the state I have this in applicationDidFinishLaunching::

for (NSArray* screen in screenList) {
    UIViewController<SaveState>* next = [[NSClassFromString([screen objectAtIndex:0]) alloc] initWithSaveState:([screen count] == 2) ? [screen objectAtIndex:1] : nil];
    if (next != nil) {
        [[self navigationController] pushViewController:next animated:NO];
        [next release];
    }
    else {
        // error handling
    }
}
Stephen Darlington