Skip to content

Instantly share code, notes, and snippets.

@djibouti33
Last active October 11, 2019 20:29
Show Gist options
  • Save djibouti33/6124370 to your computer and use it in GitHub Desktop.
Save djibouti33/6124370 to your computer and use it in GitHub Desktop.
/*
Basic setup of my app:
MMDrawerViewController (custom container view controller
LeftDrawerViewController
CenterViewController
FeaturedViewController (wrapped in a NavControlelr, initial vc at launch, but can be swapped out by interacting with menu in LeftDrawerVC)
SearchViewController (wrapped in a NavControlelr, loads within CenterVC when appropriate menu item is tapped in LeftDrawerVC)
I can get one scenario to work. as mentioned above, Featured is the first VC that is shown as a child of CenterViewController.
If I tap a button in FeaturedVC to change it's background color, when the app is restored, so is the background color.
In this scenario, here is the order of calls when encoding:
-[AppDelegate application:willEncodeRestorableStateWithCoder:]
-[MMDrawerController encodeRestorableStateWithCoder:] // it's here that i encode my left and center children view controllers
-[FeaturedViewController encodeRestorableStateWithCoder:]
-[LeftDrawerViewController encodeRestorableStateWithCoder:]
And when decoding:
+[MMDrawerController viewControllerWithRestorationIdentifierPath:coder:]
+[FeaturedViewController viewControllerWithRestorationIdentifierPath:coder:]
+[LeftDrawerViewController viewControllerWithRestorationIdentifierPath:coder:]
-[MMDrawerController decodeRestorableStateWithCoder:] // in this working scenario, decoding the coder gives me back my left and center view controllers
-[FeaturedViewController decodeRestorableStateWithCoder:]
-[LeftDrawerViewController decodeRestorableStateWithCoder:]
-[AppDelegate application:didDecodeRestorableStateWithCoder:]
In the scenario I can't get working, where I open the LeftDrawerVC, tap on Search, and the CenterVC's child is swapped out to present
SearchViewController, I'd expect, on restore, for that SearchViewController to be the child of CenterVC, but it's resetting to the FeatureViewController.
In this scenario, here is the order of calls when encoding:
-[AppDelegate application:willEncodeRestorableStateWithCoder:]
-[MMDrawerController encodeRestorableStateWithCoder:]
-[SearchViewController encodeRestorableStateWithCoder:]
-[LeftDrawerViewController encodeRestorableStateWithCoder:]
And when decoding:
+[MMDrawerController viewControllerWithRestorationIdentifierPath:coder:]
+[SearchViewController viewControllerWithRestorationIdentifierPath:coder:]
+[LeftDrawerViewController viewControllerWithRestorationIdentifierPath:coder:]
-[MMDrawerController decodeRestorableStateWithCoder:]
-[SearchViewController decodeRestorableStateWithCoder:]
-[LeftDrawerViewController decodeRestorableStateWithCoder:]
-[AppDelegate application:didDecodeRestorableStateWithCoder:]
*/
// tapping on 'Search' menu item in LeftDrawerVC
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:[SearchViewController new]];
navController.restorationIdentifier = @"centerNav";
[self.mm_drawerController setCenterViewController:navController withCloseAnimation:true completion:nil];
// restoration code in LeftDrawerViewController
- (instancetype)init
{
self = [super init];
if (self) {
self.restorationIdentifier = @"leftDrawerVC";
self.restorationClass = [self class];
}
return self;
}
+ (UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
{
return [self new];
}
// not doing any specific state encoding/decoding yet
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {}
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder {}
// restoration code in SearchViewController
- (instancetype)init
{
self = [super init];
if (self) {
self.restorationIdentifier = @"searchVC";
self.restorationClass = [self class];
}
return self;
}
+ (UIViewController *)viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
{
return [self new];
}
// not doing any specific state encoding/decoding yet
- (void)encodeRestorableStateWithCoder:(NSCoder *)coder {}
- (void)decodeRestorableStateWithCoder:(NSCoder *)coder {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment