Skip to content

Commit

Permalink
- JTRevealSidebarV2. A truly reusable solution which mimic the sideba…
Browse files Browse the repository at this point in the history
…r pattern which used by new Facebook and Path iOS app
  • Loading branch information
jamztang committed Dec 11, 2011
1 parent cf47e24 commit e7ec8c7
Show file tree
Hide file tree
Showing 24 changed files with 1,255 additions and 0 deletions.
329 changes: 329 additions & 0 deletions JTRevealSidebarDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions JTRevealSidebarDemoV2/AppDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AppDelegate.h
// JTRevealSidebarDemoV2
//
// Created by James Apple Tang on 7/12/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
70 changes: 70 additions & 0 deletions JTRevealSidebarDemoV2/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// AppDelegate.m
// JTRevealSidebarDemoV2
//
// Created by James Apple Tang on 7/12/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "AppDelegate.h"
#import "ViewController.h"

@implementation AppDelegate

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];

ViewController *controller = [[ViewController alloc] init];
controller.title = @"ViewController";
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];

self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
*/
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
*/
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}

- (void)applicationWillTerminate:(UIApplication *)application
{
/*
Called when the application is about to terminate.
Save data if appropriate.
See also applicationDidEnterBackground:.
*/
}

@end
Binary file added JTRevealSidebarDemoV2/ButtonMenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added JTRevealSidebarDemoV2/[email protected]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions JTRevealSidebarDemoV2/JTRevealSidebarDemoV2-Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFiles</key>
<array/>
<key>CFBundleIdentifier</key>
<string>com.mystcolor.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
14 changes: 14 additions & 0 deletions JTRevealSidebarDemoV2/JTRevealSidebarDemoV2-Prefix.pch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Prefix header for all source files of the 'JTRevealSidebarDemoV2' target in the 'JTRevealSidebarDemoV2' project
//

#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
16 changes: 16 additions & 0 deletions JTRevealSidebarDemoV2/NewViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// NewViewController.h
// JTRevealSidebarDemo
//
// Created by James Apple Tang on 12/12/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface NewViewController : UIViewController

@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UITableView *rightSidebarView;

@end
104 changes: 104 additions & 0 deletions JTRevealSidebarDemoV2/NewViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//
// NewViewController.m
// JTRevealSidebarDemo
//
// Created by James Apple Tang on 12/12/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "NewViewController.h"
#import "UINavigationItem+JTRevealSidebarV2.h"
#import "UIViewController+JTRevealSidebarV2.h"
#import "JTRevealSidebarV2Delegate.h"

@interface NewViewController () <JTRevealSidebarV2Delegate, UITableViewDataSource, UITableViewDelegate>
@end

@implementation NewViewController
@synthesize label;
@synthesize rightSidebarView;
#pragma mark - View lifecycle

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
self.label = [[UILabel alloc] initWithFrame:CGRectMake(30, 30, 290, 30)];
[self.view addSubview:self.label];

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(revealRightSidebar:)];

self.navigationItem.revealSidebarDelegate = self;
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

#pragma mark Action

- (void)revealRightSidebar:(id)sender {
JTRevealedState state = JTRevealedStateRight;
if (self.navigationController.revealedState == JTRevealedStateRight) {
state = JTRevealedStateNo;
}
[self.navigationController setRevealedState:state];
}


#pragma mark UITableViewDatasource

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

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if ( ! cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
}
cell.textLabel.text = [NSString stringWithFormat:@"%d", indexPath.row];
return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
if (tableView == self.rightSidebarView) {
return @"RightSidebar";
}
return nil;
}

#pragma mark UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.navigationController setRevealedState:JTRevealedStateNo];
if (tableView == self.rightSidebarView) {
self.label.text = [NSString stringWithFormat:@"Selected %d at RightSidebarView", indexPath.row];
}
}


#pragma mark JTRevealSidebarV2Delegate

- (UIView *)viewForRightSidebar {
CGRect mainFrame = [[UIScreen mainScreen] applicationFrame];
UITableView *view = self.rightSidebarView;
if ( ! view) {
view = self.rightSidebarView = [[UITableView alloc] initWithFrame:CGRectMake(160, mainFrame.origin.y, 160, mainFrame.size.height) style:UITableViewStyleGrouped];
view.dataSource = self;
view.delegate = self;
view.backgroundColor = [UIColor groupTableViewBackgroundColor];
}
return view;
}

@end
26 changes: 26 additions & 0 deletions JTRevealSidebarDemoV2/SidebarViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// LeftSidebarViewController.h
// JTRevealSidebarDemo
//
// Created by James Apple Tang on 12/12/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@protocol SidebarViewControllerDelegate;

@interface SidebarViewController : UITableViewController

@property (nonatomic, assign) id <SidebarViewControllerDelegate> sidebarDelegate;

@end

@protocol SidebarViewControllerDelegate <NSObject>

- (void)sidebarViewController:(SidebarViewController *)sidebarViewController didSelectObject:(NSObject *)object atIndexPath:(NSIndexPath *)indexPath;

@optional
- (NSIndexPath *)lastSelectedIndexPathForSidebarViewController:(SidebarViewController *)sidebarViewController;

@end
86 changes: 86 additions & 0 deletions JTRevealSidebarDemoV2/SidebarViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// LeftSidebarViewController.m
// JTRevealSidebarDemo
//
// Created by James Apple Tang on 12/12/11.
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//

#import "SidebarViewController.h"


@implementation SidebarViewController
@synthesize sidebarDelegate;

- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}

#pragma mark - View lifecycle

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

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

if ([self.sidebarDelegate respondsToSelector:@selector(lastSelectedIndexPathForSidebarViewController:)]) {
NSIndexPath *indexPath = [self.sidebarDelegate lastSelectedIndexPathForSidebarViewController:self];
[self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

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

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [NSString stringWithFormat:@"ViewController%d", indexPath.row];

return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return self.title;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.sidebarDelegate) {
NSObject *object = [NSString stringWithFormat:@"ViewController%d", indexPath.row];
[self.sidebarDelegate sidebarViewController:self didSelectObject:object atIndexPath:indexPath];
}
}

@end
Loading

0 comments on commit e7ec8c7

Please sign in to comment.