views:

264

answers:

2

Hello Everyone,

Following is what i am doing:

- (void) applicationWillTerminate: (UIApplication*) application {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:navigationController.viewControllers
        forKey:@"diabetesstate"];
}

- (void) applicationDidFinishLaunching: (UIApplication*) application {
    NSMutableArray *state = [[NSUserDefaults standardUserDefaults] 
        objectForKey:@"diabetesstate"];
    if (state == nil) {
        //Will initialize a new controller and put it as root view controller
    }
    else {
        [navigationController setViewControllers:state animated:NO];
    }
}
+1  A: 

It looks like you're trying to add a UIViewController to the userdefaults? I doubt that will work.

I guess you'll have to put some identifer string or number in there that tells you which viewcontroller is currently displayed, and when the application starts basically check that value and set up your viewcontrollers accordingly.

I need to implement something similar for my application. I've got a list of objects, and when the user taps on one I am displaying a child object. My idea is to store the ID of the client object if one is currently being displayed, otherwise NULL. When the application starts I will check the value. If it's NULL I'll display the list of parent objects, otherwise I'll show the child object with the ID that's in userdefaults.

Thomas Müller