Skip to content

Commit

Permalink
Basics for state preservation / restoration setup.
Browse files Browse the repository at this point in the history
Not complete.
Workaround in SWRevealController, toggle rearView twice as a work around.
The state of the menu works.
the framework methods are getting called in the other pages, but haven’t debugged them.
  • Loading branch information
rochbu committed Jul 9, 2014
1 parent af01c7b commit 08cd2c5
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<!--Reveal View Controller-->
<scene sceneID="kQx-iy-tfG">
<objects>
<viewController id="BnE-t1-cO2" customClass="SWRevealViewController" sceneMemberID="viewController">
<viewController storyboardIdentifier="SWRevealViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="BnE-t1-cO2" customClass="SWRevealViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="AqQ-ZN-66p">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
Expand All @@ -26,8 +26,8 @@
<!--Menu View Controller-->
<scene sceneID="MRh-rO-dc1">
<objects>
<tableViewController id="QF7-9c-pUP" customClass="MenuViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="zp3-JK-cpb">
<tableViewController storyboardIdentifier="MenuViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="QF7-9c-pUP" customClass="MenuViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="MenuTableView" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="zp3-JK-cpb">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
Expand Down Expand Up @@ -117,7 +117,7 @@
<!--Color View Controller - iPad Color-->
<scene sceneID="a2e-Aa-0Nf">
<objects>
<viewController id="ziO-d3-BPQ" customClass="ColorViewController" sceneMemberID="viewController">
<viewController storyboardIdentifier="ColorViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="ziO-d3-BPQ" customClass="ColorViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="pIg-cU-tR4">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES" flexibleMaxY="YES"/>
Expand Down Expand Up @@ -147,7 +147,7 @@
<!--Navigation Controller-->
<scene sceneID="9JS-IT-HOR">
<objects>
<navigationController definesPresentationContext="YES" id="nyM-DF-G37" sceneMemberID="viewController">
<navigationController storyboardIdentifier="NavigationControllerMap" definesPresentationContext="YES" useStoryboardIdentifierAsRestorationIdentifier="YES" id="nyM-DF-G37" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="RQv-y7-19i">
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
Expand All @@ -162,7 +162,7 @@
<!--Map View Controller - iPad Map-->
<scene sceneID="hHE-Es-ToG">
<objects>
<viewController id="dN4-6k-5wY" customClass="MapViewController" sceneMemberID="viewController">
<viewController storyboardIdentifier="MapViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="dN4-6k-5wY" customClass="MapViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Ikb-if-QnY">
<rect key="frame" x="0.0" y="0.0" width="768" height="1024"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
Expand All @@ -189,8 +189,8 @@
<!--Navigation Controller-->
<scene sceneID="2Et-ek-LeJ">
<objects>
<navigationController definesPresentationContext="YES" id="rrL-rJ-NYi" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" id="cwG-Nk-Jya">
<navigationController storyboardIdentifier="NavigationControllerColor" definesPresentationContext="YES" useStoryboardIdentifierAsRestorationIdentifier="YES" id="rrL-rJ-NYi" sceneMemberID="viewController">
<navigationBar key="navigationBar" contentMode="scaleToFill" restorationIdentifier="NavigationBar" id="cwG-Nk-Jya">
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<connections>
Expand Down
65 changes: 65 additions & 0 deletions SWRevealViewController/SWRevealViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 08cd2c5

Please sign in to comment.