diff --git a/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/AppDelegate.m b/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/AppDelegate.m index 849fb72..55dc092 100755 --- a/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/AppDelegate.m +++ b/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/AppDelegate.m @@ -43,4 +43,18 @@ - (void)applicationWillTerminate:(UIApplication *)application // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } +#pragma mark state preservation / restoration +- (BOOL) application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder { + return YES; +} + +- (BOOL) application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder { + return YES; +} + +- (BOOL) application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + + [self.window makeKeyAndVisible]; + return YES; +} @end diff --git a/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/ColorViewController.m b/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/ColorViewController.m index 99ba03a..d024cf4 100755 --- a/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/ColorViewController.m +++ b/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/ColorViewController.m @@ -26,4 +26,30 @@ - (void)viewDidLoad _label.textColor = _color; } +#pragma mark state preservation / restoration +- (void)encodeRestorableStateWithCoder:(NSCoder *)coder { + NSLog(@"%s", __PRETTY_FUNCTION__); + + // TODO save what you need here + [coder encodeObject: _label.text forKey: @"lableText"]; + + [super encodeRestorableStateWithCoder:coder]; +} + +- (void)decodeRestorableStateWithCoder:(NSCoder *)coder { + NSLog(@"%s", __PRETTY_FUNCTION__); + + // TODO restore what you need here + _label.text = [coder decodeObjectForKey: @"labelText"]; + + [super decodeRestorableStateWithCoder:coder]; +} + +- (void)applicationFinishedRestoringState { + NSLog(@"%s", __PRETTY_FUNCTION__); + + // TODO call whatever function you need to visually restore + +} + @end diff --git a/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/MapViewController.m b/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/MapViewController.m index 482f026..e1bf9c6 100755 --- a/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/MapViewController.m +++ b/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/MapViewController.m @@ -23,4 +23,27 @@ - (void)viewDidLoad [self.navigationController.navigationBar addGestureRecognizer: self.revealViewController.panGestureRecognizer]; } +#pragma mark state preservation / restoration +- (void)encodeRestorableStateWithCoder:(NSCoder *)coder { + NSLog(@"%s", __PRETTY_FUNCTION__); + + // TODO save what you need here + + [super encodeRestorableStateWithCoder:coder]; +} + +- (void)decodeRestorableStateWithCoder:(NSCoder *)coder { + NSLog(@"%s", __PRETTY_FUNCTION__); + + // TODO restore what you need here + + [super decodeRestorableStateWithCoder:coder]; +} + +- (void)applicationFinishedRestoringState { + NSLog(@"%s", __PRETTY_FUNCTION__); + + // TODO call whatever function you need to visually restore +} + @end diff --git a/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/MenuViewController.m b/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/MenuViewController.m index c3e0512..072b6a9 100755 --- a/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/MenuViewController.m +++ b/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/MenuViewController.m @@ -99,4 +99,27 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N return cell; } +#pragma mark state preservation / restoration +- (void)encodeRestorableStateWithCoder:(NSCoder *)coder { + NSLog(@"%s", __PRETTY_FUNCTION__); + + // TODO save what you need here + + [super encodeRestorableStateWithCoder:coder]; +} + +- (void)decodeRestorableStateWithCoder:(NSCoder *)coder { + NSLog(@"%s", __PRETTY_FUNCTION__); + + // TODO restore what you need here + + [super decodeRestorableStateWithCoder:coder]; +} + +- (void)applicationFinishedRestoringState { + NSLog(@"%s", __PRETTY_FUNCTION__); + + // TODO call whatever function you need to visually restore +} + @end diff --git a/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/en.lproj/MainStoryboard-iPad.storyboard b/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/en.lproj/MainStoryboard-iPad.storyboard index 5e5cfe2..c9deb5f 100755 --- a/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/en.lproj/MainStoryboard-iPad.storyboard +++ b/RevealControllerStoryboardExample2/RevealControllerStoryboardExample2/en.lproj/MainStoryboard-iPad.storyboard @@ -8,7 +8,7 @@ - + @@ -26,8 +26,8 @@ - - + + @@ -117,7 +117,7 @@ - + @@ -147,7 +147,7 @@ - + @@ -162,7 +162,7 @@ - + @@ -189,8 +189,8 @@ - - + + diff --git a/SWRevealViewController/SWRevealViewController.m b/SWRevealViewController/SWRevealViewController.m index 802ccc5..84bc5fc 100755 --- a/SWRevealViewController/SWRevealViewController.m +++ b/SWRevealViewController/SWRevealViewController.m @@ -1643,6 +1643,71 @@ - (void)loadStoryboardControllers } } +#pragma mark state preservation / restoration ++ (UIViewController*) viewControllerWithRestorationIdentifierPath:(NSArray*) identifierComponents coder:(NSCoder*)coder { + NSLog(@"%s", __PRETTY_FUNCTION__); + + SWRevealViewController* vc; + UIStoryboard* sb = [coder decodeObjectForKey:UIStateRestorationViewControllerStoryboardKey]; + + if (sb) { + vc = (SWRevealViewController*)[sb instantiateViewControllerWithIdentifier:@"SWRevealViewController"]; + vc.restorationIdentifier = [identifierComponents lastObject]; + vc.restorationClass = [SWRevealViewController class]; + } + return vc; +} + +- (void)encodeRestorableStateWithCoder:(NSCoder *)coder { + + // this will include the other view controllers in state encoding and decoding + if (_rearViewController) { + [coder encodeObject: _rearViewController forKey: @"rearViewController"]; + } + + if (_frontViewController) { + [coder encodeObject: _frontViewController forKey: @"frontViewController"]; + } + + if (_rightViewController) { + [coder encodeObject: _rightViewController forKey: @"rightViewController"]; + } + + // ??? What's needed to restore what position the views are in + [coder encodeInt: _frontViewPosition forKey: @"frontViewPosition"]; + [coder encodeInt: _rearViewPosition forKey: @"rearViewPosition"]; + [coder encodeInt: _rightViewPosition forKey: @"rightViewPosition"]; + + [super encodeRestorableStateWithCoder:coder]; +} + +- (void)decodeRestorableStateWithCoder:(NSCoder *)coder { + + // ??? What's needed to restore what position the views are in + _frontViewPosition = [coder decodeIntForKey: @"frontViewPosition"]; + _rearViewPosition = [coder decodeIntForKey: @"rearViewPosition"]; + _rightViewPosition = [coder decodeIntForKey: @"rightViewPosition"]; + + [super decodeRestorableStateWithCoder:coder]; +} + +- (void)applicationFinishedRestoringState { + + // ??? Get the views to where they should be + + [self _setFrontViewPosition: _frontViewPosition withDuration:0.0]; + + [self revealToggleAnimated: NO]; + [self revealToggleAnimated: NO]; + +// if (_rearViewPosition != FrontViewPositionNone) { +// [self revealToggleAnimated: NO]; +// } +// +// if (_rightViewPosition >= FrontViewPositionLeft) { +// [self rightRevealToggleAnimated: NO]; +// } +} @end