Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a identifier to save the state for Menue item controllers. #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion SWRevealViewController/SWRevealViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@


#import <UIKit/UIKit.h>
#import <objc/runtime.h>

@class SWRevealViewController;
@protocol SWRevealViewControllerDelegate;
Expand Down Expand Up @@ -309,6 +310,8 @@ typedef NS_ENUM(NSInteger, SWRevealToggleAnimationType)
// Delegate
@property (nonatomic,weak) id<SWRevealViewControllerDelegate> delegate;

@property (nonatomic, strong) NSMutableDictionary *sidebarItems;

@end


Expand Down Expand Up @@ -386,11 +389,12 @@ typedef enum
// A category of UIViewController to let childViewControllers easily access their parent SWRevealViewController
@interface UIViewController(SWRevealViewController)

@property (nonatomic, assign) id controllerIdentifier;

- (SWRevealViewController*)revealViewController;

@end


#pragma mark - StoryBoard support Classes

/* StoryBoard support */
Expand Down
32 changes: 32 additions & 0 deletions SWRevealViewController/SWRevealViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ - (void)_initDefaultProperties
_draggableBorderWidth = 0.0f;
_clipsViewsToBounds = NO;
_extendsPointInsideHit = NO;
_sidebarItems = [NSMutableDictionary new];
}


Expand Down Expand Up @@ -1779,8 +1780,22 @@ - (void)applicationFinishedRestoringState

#pragma mark - UIViewController(SWRevealViewController) Category

NSString * const kControllerIdentifierKey = @"kControllerIdentifierKey";

@implementation UIViewController(SWRevealViewController)

@dynamic controllerIdentifier;

- (void)setControllerIdentifier:(id)aObject
{
objc_setAssociatedObject(self, (__bridge const void *)(kControllerIdentifierKey), aObject, OBJC_ASSOCIATION_ASSIGN);
}

- (id)controllerIdentifier
{
return objc_getAssociatedObject(self, (__bridge const void *)(kControllerIdentifierKey));
}

- (SWRevealViewController*)revealViewController
{
UIViewController *parent = self;
Expand Down Expand Up @@ -1811,6 +1826,14 @@ - (void)perform
SWRevealViewController *rvc = self.sourceViewController;
UIViewController *dvc = self.destinationViewController;

if (dvc.controllerIdentifier) {

if (![[rvc.sidebarItems allKeys] containsObject:self.identifier])
[rvc.sidebarItems setObject:dvc forKey:self.identifier];
else
dvc = [rvc.sidebarItems objectForKey:self.identifier];
}

if ( [identifier isEqualToString:SWSegueFrontIdentifier] )
operation = SWRevealControllerOperationReplaceFrontController;

Expand All @@ -1835,6 +1858,15 @@ - (void)perform
{
SWRevealViewController *rvc = [self.sourceViewController revealViewController];
UIViewController *dvc = self.destinationViewController;

if (dvc.controllerIdentifier) {

if (![[rvc.sidebarItems allKeys] containsObject:self.identifier])
[rvc.sidebarItems setObject:dvc forKey:self.identifier];
else
dvc = [rvc.sidebarItems objectForKey:self.identifier];
}

[rvc pushFrontViewController:dvc animated:YES];
}

Expand Down