Skip to content

Commit

Permalink
Updated example to use Restoration
Browse files Browse the repository at this point in the history
  • Loading branch information
kcharwood committed Aug 2, 2013
1 parent 316e235 commit b850b8d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 16 deletions.
69 changes: 54 additions & 15 deletions KitchenSink/ExampleFiles/MMAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,51 @@

#import <QuartzCore/QuartzCore.h>

@implementation MMAppDelegate
@interface MMAppDelegate ()

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
@property (nonatomic,strong) MMDrawerController * drawerController;

@end

@implementation MMAppDelegate
-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
UIViewController * leftSideDrawerViewController = [[MMExampleLeftSideDrawerViewController alloc] init];

UIViewController * centerViewController = [[MMExampleCenterTableViewController alloc] initWithStyle:UITableViewStyleGrouped];

UIViewController * rightSideDrawerViewController = [[MMExampleRightSideDrawerViewController alloc] init];

UINavigationController * navigationController = [[UINavigationController alloc] initWithRootViewController:centerViewController];
[navigationController setRestorationIdentifier:@"MMExampleCenterNavigationControllerRestorationKey"];

MMDrawerController * drawerController = [[MMDrawerController alloc]
initWithCenterViewController:navigationController
leftDrawerViewController:leftSideDrawerViewController
rightDrawerViewController:rightSideDrawerViewController];
[drawerController setMaximumRightDrawerWidth:200.0];
[drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
self.drawerController = [[MMDrawerController alloc]
initWithCenterViewController:navigationController
leftDrawerViewController:leftSideDrawerViewController
rightDrawerViewController:rightSideDrawerViewController];
[self.drawerController setRestorationIdentifier:@"MMDrawer"];
[self.drawerController setMaximumRightDrawerWidth:200.0];
[self.drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
[self.drawerController setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];

[drawerController
[self.drawerController
setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
MMDrawerControllerDrawerVisualStateBlock block;
block = [[MMExampleDrawerVisualStateManager sharedManager]
drawerVisualStateBlockForDrawerSide:drawerSide];
drawerVisualStateBlockForDrawerSide:drawerSide];
if(block){
block(drawerController, drawerSide, percentVisible);
}
}];

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setRootViewController:drawerController];
// Override point for customization after application launch.
[self.window setRootViewController:self.drawerController];

return YES;
}


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
Expand Down Expand Up @@ -94,4 +106,31 @@ - (void)applicationWillTerminate:(UIApplication *)application
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (BOOL)application:(UIApplication *)application shouldSaveApplicationState:(NSCoder *)coder{
return YES;
}

- (BOOL)application:(UIApplication *)application shouldRestoreApplicationState:(NSCoder *)coder{
return YES;
}


- (UIViewController *)application:(UIApplication *)application viewControllerWithRestorationIdentifierPath:(NSArray *)identifierComponents coder:(NSCoder *)coder
{
NSString * key = [identifierComponents lastObject];
if([key isEqualToString:@"MMDrawer"]){
return self.window.rootViewController;
}
else if ([key isEqualToString:@"MMExampleCenterNavigationControllerRestorationKey"]) {
return ((MMDrawerController *)self.window.rootViewController).centerViewController;
}
else if ([key isEqualToString:@"MMExampleLeftSideDrawerController"]){
return ((MMDrawerController *)self.window.rootViewController).leftDrawerViewController;
}
else if ([key isEqualToString:@"MMExampleRightSideDrawerController"]){
return ((MMDrawerController *)self.window.rootViewController).rightDrawerViewController;
}
return nil;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ - (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
[self setRestorationIdentifier:@"MMExampleCenterControllerRestorationKey"];
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ @interface MMExampleLeftSideDrawerViewController ()

@implementation MMExampleLeftSideDrawerViewController

-(id)init{
self = [super init];
if(self){
[self setRestorationIdentifier:@"MMExampleLeftSideDrawerController"];
}
return self;
}

-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
NSLog(@"Left will appear");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ @interface MMExampleRightSideDrawerViewController ()
@end

@implementation MMExampleRightSideDrawerViewController
-(id)init{
self = [super init];
if(self){
[self setRestorationIdentifier:@"MMExampleRightSideDrawerController"];
}
return self;
}

-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
Expand Down

0 comments on commit b850b8d

Please sign in to comment.