Skip to content

State Restoration #65

Closed
Closed
@djibouti33

Description

@djibouti33

Hey there,

First off, thanks so much for the work you've done with this library. So simple to use and such a nice lib.

I'm trying to add State Restoration to my app and am running into a problem. I'm not sure if it's in the code (the state restoration machinery) that I've set up or if something unexpected is happening in your lib that I'm not aware of (I haven't been able to find anything yet).

I have an SO question open: m/questions/17934668/ios-state-restoration-with-custom-container-view-controller-mmdrawercontroller but I'll also post here since it will be easier to talk about.

I've added this to MMDrawerController:

- (void)encodeRestorableStateWithCoder:(NSCoder *)coder
{
    [coder encodeObject:self.centerViewController forKey:@"centerVC"];
    [coder encodeObject:self.leftDrawerViewController forKey:@"leftDrawerVC"];
    [super encodeRestorableStateWithCoder:coder];
}

- (void)decodeRestorableStateWithCoder:(NSCoder *)coder
{
    // these values log out fine if I don't interact with the left Drawer.
    // if i do, they wind up being null
    NSLog(@"leftDrawer: %@", [coder decodeObjectForKey:@"leftDrawerVC"]);
    NSLog(@"center: %@", [coder decodeObjectForKey:@"centerVC"]);
    [super decodeRestorableStateWithCoder:coder];
}

Essentially I'm storing the left and center view controllers so that when restoration happens, I can get them back and add them to the main MMDrawerController.

In the first CenterViewController that loads, I added two buttons that change the color of the background. I can change it to red, for example, kill the app, and come back in and the background is still red. Perfect.

However, if I open the left drawer, and select an item which swaps out the center view controller, when I quit the app and come back in, during restoration the two logs in decodeRestorableStateWithCoder are now null.

For some reason changing out the center view controller messes with the coder.

Again, I'm not sure if the problem is in my code or if something unexpected is happening, but I've been on this for a few days and figure I should ask.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions