Skip to content

Commit

Permalink
v2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan Lluch committed Aug 15, 2014
1 parent ce08628 commit 86d5bc5
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 335 deletions.
143 changes: 73 additions & 70 deletions RevealControllerExample/RevealControllerProject/RearViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ of this software and associated documentation files (the "Software"), to deal
#import "MapViewController.h"

@interface RearViewController()
{
NSInteger _presentedRow;
}

@end

Expand All @@ -46,104 +49,104 @@ @implementation RearViewController

- (void)viewDidLoad
{
[super viewDidLoad];
[super viewDidLoad];

self.title = NSLocalizedString(@"Rear View", nil);
self.title = NSLocalizedString(@"Rear View", nil);
}


#pragma marl - UITableView Data Source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 4;
return 4;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
NSInteger row = indexPath.row;

if (nil == cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
}

if (nil == cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentifier];
}

if (row == 0)
{
cell.textLabel.text = @"Front View Controller";
}
else if (row == 1)
{
cell.textLabel.text = @"Map View Controller";
}
else if (row == 2)
{
cell.textLabel.text = @"Enter Presentation Mode";
}
else if (row == 3)
{
cell.textLabel.text = @"Resign Presentation Mode";
}
NSString *text = nil;
if (row == 0)
{
text = @"Front View Controller";
}
else if (row == 1)
{
text = @"Map View Controller";
}
else if (row == 2)
{
text = @"Enter Presentation Mode";
}
else if (row == 3)
{
text = @"Resign Presentation Mode";
}

cell.textLabel.text = NSLocalizedString( text,nil );

return cell;
return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Grab a handle to the reveal controller, as if you'd do with a navigtion controller via self.navigationController.
// Grab a handle to the reveal controller, as if you'd do with a navigtion controller via self.navigationController.
SWRevealViewController *revealController = self.revealViewController;

// We know the frontViewController is a NavigationController
UINavigationController *frontNavigationController = (id)revealController.frontViewController; // <-- we know it is a NavigationController
// selecting row
NSInteger row = indexPath.row;

// Here you'd implement some of your own logic... I simply take for granted that the first row (=0) corresponds to the "FrontViewController".
if (row == 0)
{
// Now let's see if we're not attempting to swap the current frontViewController for a new instance of ITSELF, which'd be highly redundant.
if ( ![frontNavigationController.topViewController isKindOfClass:[FrontViewController class]] )
{
FrontViewController *frontViewController = [[FrontViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
[revealController pushFrontViewController:navigationController animated:YES];
}
// Seems the user attempts to 'switch' to exactly the same controller he came from!
else
{
[revealController revealToggle:self];
}
}

// ... and the second row (=1) corresponds to the "MapViewController".
else if (row == 1)
{
// Now let's see if we're not attempting to swap the current frontViewController for a new instance of ITSELF, which'd be highly redundant.
if ( ![frontNavigationController.topViewController isKindOfClass:[MapViewController class]] )
{
MapViewController *mapViewController = [[MapViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mapViewController];
[revealController pushFrontViewController:navigationController animated:YES];
}

// Seems the user attempts to 'switch' to exactly the same controller he came from!
else
{
[revealController revealToggle:self];
}
}
else if (row == 2)
{
// if we are trying to push the same row or perform an operation that does not imply frontViewController replacement
// we'll just set position and return

if ( row == _presentedRow )
{
[revealController setFrontViewPosition:FrontViewPositionLeft animated:YES];
return;
}
else if (row == 2)
{
[revealController setFrontViewPosition:FrontViewPositionRightMost animated:YES];
}
else if (row == 3)
{
return;
}
else if (row == 3)
{
[revealController setFrontViewPosition:FrontViewPositionRight animated:YES];
}
return;
}

// otherwise we'll create a new frontViewController and push it with animation

UIViewController *newFrontController = nil;

if (row == 0)
{
newFrontController = [[FrontViewController alloc] init];
}

else if (row == 1)
{
newFrontController = [[MapViewController alloc] init];
}

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:newFrontController];
[revealController pushFrontViewController:navigationController animated:YES];

_presentedRow = row; // <- store the presented row
}



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

0 comments on commit 86d5bc5

Please sign in to comment.