Permalink
Browse files

- show how menu table view can be styled in demo app

- fold menu table view automatically when an item is selected
- added a delegate method to ask if menu table view should be collapsed when an item is selected
- added a method to fold/unfold menu table view with/without animation
- removed redundant view controllers in demo
  • Loading branch information...
1 parent e3afdb8 commit f14c2534f5170156ef3fe7001ec3b5d9f18cc08d @honcheng committed Oct 27, 2012
@@ -29,11 +29,11 @@
F893850B163AD49E0085C3BB /* ShadowView.m in Sources */ = {isa = PBXBuildFile; fileRef = F89384FD163AD49E0085C3BB /* ShadowView.m */; };
F893850C163AD49E0085C3BB /* TouchThroughUIView.m in Sources */ = {isa = PBXBuildFile; fileRef = F89384FF163AD49E0085C3BB /* TouchThroughUIView.m */; };
F893850D163AD49E0085C3BB /* UIView+Screenshot.m in Sources */ = {isa = PBXBuildFile; fileRef = F8938501163AD49E0085C3BB /* UIView+Screenshot.m */; };
- F8938513163AD5CE0085C3BB /* FirstViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F8938512163AD5CE0085C3BB /* FirstViewController.m */; };
- F8938516163AD5D70085C3BB /* SecondViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F8938515163AD5D70085C3BB /* SecondViewController.m */; };
- F8938519163AD5E20085C3BB /* ThirdViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F8938518163AD5E10085C3BB /* ThirdViewController.m */; };
F8938535163AD6FA0085C3BB /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8938534163AD6FA0085C3BB /* QuartzCore.framework */; };
F893853C163AD8680085C3BB /* DemoMenuController.m in Sources */ = {isa = PBXBuildFile; fileRef = F893853B163AD8680085C3BB /* DemoMenuController.m */; };
+ F8C000CF163B67DF00654C1E /* cellBg@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F8C000CE163B67DF00654C1E /* cellBg@2x.png */; };
+ F8C000D3163B691E00654C1E /* cellBgSelected@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F8C000D2163B691E00654C1E /* cellBgSelected@2x.png */; };
+ F8C000D6163B6B7300654C1E /* DemoRootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F8C000D5163B6B7300654C1E /* DemoRootViewController.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
@@ -73,16 +73,14 @@
F89384FF163AD49E0085C3BB /* TouchThroughUIView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TouchThroughUIView.m; sourceTree = "<group>"; };
F8938500163AD49E0085C3BB /* UIView+Screenshot.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+Screenshot.h"; sourceTree = "<group>"; };
F8938501163AD49E0085C3BB /* UIView+Screenshot.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIView+Screenshot.m"; sourceTree = "<group>"; };
- F8938511163AD5CE0085C3BB /* FirstViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FirstViewController.h; sourceTree = "<group>"; };
- F8938512163AD5CE0085C3BB /* FirstViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FirstViewController.m; sourceTree = "<group>"; };
- F8938514163AD5D70085C3BB /* SecondViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SecondViewController.h; sourceTree = "<group>"; };
- F8938515163AD5D70085C3BB /* SecondViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SecondViewController.m; sourceTree = "<group>"; };
- F8938517163AD5E10085C3BB /* ThirdViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThirdViewController.h; sourceTree = "<group>"; };
- F8938518163AD5E10085C3BB /* ThirdViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ThirdViewController.m; sourceTree = "<group>"; };
F8938534163AD6FA0085C3BB /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
F893853A163AD8680085C3BB /* DemoMenuController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoMenuController.h; sourceTree = "<group>"; };
F893853B163AD8680085C3BB /* DemoMenuController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoMenuController.m; sourceTree = "<group>"; };
F8938557163ADFE40085C3BB /* PaperFoldMenuControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PaperFoldMenuControllerDelegate.h; path = ../PaperFoldMenuController/PaperFoldMenuControllerDelegate.h; sourceTree = "<group>"; };
+ F8C000CE163B67DF00654C1E /* cellBg@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "cellBg@2x.png"; sourceTree = "<group>"; };
+ F8C000D2163B691E00654C1E /* cellBgSelected@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "cellBgSelected@2x.png"; sourceTree = "<group>"; };
+ F8C000D4163B6B7300654C1E /* DemoRootViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemoRootViewController.h; sourceTree = "<group>"; };
+ F8C000D5163B6B7300654C1E /* DemoRootViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DemoRootViewController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -136,12 +134,8 @@
F8938467163AD2BE0085C3BB /* AppDelegate.m */,
F893853A163AD8680085C3BB /* DemoMenuController.h */,
F893853B163AD8680085C3BB /* DemoMenuController.m */,
- F8938511163AD5CE0085C3BB /* FirstViewController.h */,
- F8938512163AD5CE0085C3BB /* FirstViewController.m */,
- F8938514163AD5D70085C3BB /* SecondViewController.h */,
- F8938515163AD5D70085C3BB /* SecondViewController.m */,
- F8938517163AD5E10085C3BB /* ThirdViewController.h */,
- F8938518163AD5E10085C3BB /* ThirdViewController.m */,
+ F8C000D4163B6B7300654C1E /* DemoRootViewController.h */,
+ F8C000D5163B6B7300654C1E /* DemoRootViewController.m */,
F893845E163AD2BE0085C3BB /* Supporting Files */,
);
path = Demo;
@@ -150,6 +144,8 @@
F893845E163AD2BE0085C3BB /* Supporting Files */ = {
isa = PBXGroup;
children = (
+ F8C000CE163B67DF00654C1E /* cellBg@2x.png */,
+ F8C000D2163B691E00654C1E /* cellBgSelected@2x.png */,
F893845F163AD2BE0085C3BB /* Demo-Info.plist */,
F8938460163AD2BE0085C3BB /* InfoPlist.strings */,
F8938463163AD2BE0085C3BB /* main.m */,
@@ -267,6 +263,8 @@
F8938506163AD49E0085C3BB /* PaperFoldResources.bundle in Resources */,
F8938509163AD49E0085C3BB /* swipe_guide.psd in Resources */,
F893850A163AD49E0085C3BB /* swipe_guide2.psd in Resources */,
+ F8C000CF163B67DF00654C1E /* cellBg@2x.png in Resources */,
+ F8C000D3163B691E00654C1E /* cellBgSelected@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -289,10 +287,8 @@
F893850B163AD49E0085C3BB /* ShadowView.m in Sources */,
F893850C163AD49E0085C3BB /* TouchThroughUIView.m in Sources */,
F893850D163AD49E0085C3BB /* UIView+Screenshot.m in Sources */,
- F8938513163AD5CE0085C3BB /* FirstViewController.m in Sources */,
- F8938516163AD5D70085C3BB /* SecondViewController.m in Sources */,
- F8938519163AD5E20085C3BB /* ThirdViewController.m in Sources */,
F893853C163AD8680085C3BB /* DemoMenuController.m in Sources */,
+ F8C000D6163B6B7300654C1E /* DemoRootViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
@@ -7,36 +7,28 @@
//
#import "AppDelegate.h"
-#import "FirstViewController.h"
-#import "SecondViewController.h"
-#import "ThirdViewController.h"
+#import "DemoMenuController.h"
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- _menuController = [[DemoMenuController alloc] initWithMenuWidth:250.0];
+ _menuController = [[DemoMenuController alloc] initWithMenuWidth:250.0 numberOfFolds:3];
[_menuController setDelegate:self];
[self.window setRootViewController:_menuController];
NSMutableArray *viewControllers = [NSMutableArray array];
- FirstViewController *firstViewController = [[FirstViewController alloc] init];
- [firstViewController setTitle:@"First View Controller"];
- UINavigationController *firstNavController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
- [viewControllers addObject:firstNavController];
+ for (int i=0; i<8; i++)
+ {
+ DemoMenuController *rootViewController = [[DemoMenuController alloc] init];
+ [rootViewController setTitle:[NSString stringWithFormat:@"Root VC %i", i+1]];
+ UINavigationController *rootNavController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
+ [viewControllers addObject:rootNavController];
+ }
- SecondViewController *secondViewController = [[SecondViewController alloc] init];
- [secondViewController setTitle:@"Second View Controller"];
- UINavigationController *secondNavController = [[UINavigationController alloc] initWithRootViewController:secondViewController];
- [viewControllers addObject:secondNavController];
-
- ThirdViewController *thirdViewController = [[ThirdViewController alloc] init];
- [thirdViewController setTitle:@"Third View Controller"];
- UINavigationController *thirdNavController = [[UINavigationController alloc] initWithRootViewController:thirdViewController];
- [viewControllers addObject:thirdNavController];
[_menuController setViewControllers:viewControllers];
@@ -14,25 +14,58 @@ @interface DemoMenuController ()
@implementation DemoMenuController
-- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
+- (id)initWithMenuWidth:(float)menuWidth numberOfFolds:(int)numberOfFolds
{
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
+ self = [super initWithMenuWidth:menuWidth numberOfFolds:numberOfFolds];
+ if (self)
+ {
+ UIView *tableBgView = [[UIView alloc] init];
+ [tableBgView setBackgroundColor:[UIColor colorWithRed:0.170 green:0.166 blue:0.175 alpha:1.000]];
+ [self.menuTableView setBackgroundView:tableBgView];
+ [self.menuTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}
return self;
}
-- (void)viewDidLoad
+- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
- [super viewDidLoad];
- // Do any additional setup after loading the view.
+ return 50;
}
-- (void)didReceiveMemoryWarning
+/**
+ * Override the method to customize cells
+ */
+- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
+ if (tableView==self.menuTableView)
+ {
+ static NSString *identifier = @"identifier";
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
+ if (!cell)
+ {
+ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
+ [[cell textLabel] setTextColor:[UIColor whiteColor]];
+ [[cell textLabel] setHighlightedTextColor:[UIColor blackColor]];
+
+ UIImageView *bgView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"cellBg.png"] stretchableImageWithLeftCapWidth:20 topCapHeight:20]];
+ [cell setBackgroundView:bgView];
+ UIImageView *sBgView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"cellBgSelected.png"] stretchableImageWithLeftCapWidth:20 topCapHeight:20]];
+ [cell setSelectedBackgroundView:sBgView];
+
+ }
+
+ UIViewController *viewController = self.viewControllers[indexPath.row];
+ [cell.textLabel setText:viewController.title];
+
+ if (indexPath.row==self.selectedIndex)
+ {
+ [tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
+ }
+
+ return cell;
+ }
+ else return nil;
}
+
@end
@@ -0,0 +1,13 @@
+//
+// DemoRootViewController.h
+// Demo
+//
+// Created by honcheng on 27/10/12.
+// Copyright (c) 2012 Hon Cheng Muh. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface DemoRootViewController : UIViewController
+
+@end
@@ -1,18 +1,18 @@
//
-// ThirdViewController.m
+// DemoRootViewController.m
// Demo
//
-// Created by honcheng on 26/10/12.
+// Created by honcheng on 27/10/12.
// Copyright (c) 2012 Hon Cheng Muh. All rights reserved.
//
-#import "ThirdViewController.h"
+#import "DemoRootViewController.h"
-@interface ThirdViewController ()
+@interface DemoRootViewController ()
@end
-@implementation ThirdViewController
+@implementation DemoRootViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
@@ -1,13 +0,0 @@
-//
-// FirstViewController.h
-// Demo
-//
-// Created by honcheng on 26/10/12.
-// Copyright (c) 2012 Hon Cheng Muh. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-@interface FirstViewController : UIViewController
-
-@end
@@ -1,38 +0,0 @@
-//
-// FirstViewController.m
-// Demo
-//
-// Created by honcheng on 26/10/12.
-// Copyright (c) 2012 Hon Cheng Muh. All rights reserved.
-//
-
-#import "FirstViewController.h"
-
-@interface FirstViewController ()
-
-@end
-
-@implementation FirstViewController
-
-- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
-{
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
-}
-
-- (void)viewDidLoad
-{
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-}
-
-- (void)didReceiveMemoryWarning
-{
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
-}
-
-@end
@@ -1,13 +0,0 @@
-//
-// SecondViewController.h
-// Demo
-//
-// Created by honcheng on 26/10/12.
-// Copyright (c) 2012 Hon Cheng Muh. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-@interface SecondViewController : UIViewController
-
-@end
@@ -1,38 +0,0 @@
-//
-// SecondViewController.m
-// Demo
-//
-// Created by honcheng on 26/10/12.
-// Copyright (c) 2012 Hon Cheng Muh. All rights reserved.
-//
-
-#import "SecondViewController.h"
-
-@interface SecondViewController ()
-
-@end
-
-@implementation SecondViewController
-
-- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
-{
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
-}
-
-- (void)viewDidLoad
-{
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-}
-
-- (void)didReceiveMemoryWarning
-{
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
-}
-
-@end
@@ -1,13 +0,0 @@
-//
-// ThirdViewController.h
-// Demo
-//
-// Created by honcheng on 26/10/12.
-// Copyright (c) 2012 Hon Cheng Muh. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-@interface ThirdViewController : UIViewController
-
-@end
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -54,5 +54,11 @@
* This method initialize the view controller with
* the width of the menu table view on the left
*/
-- (id)initWithMenuWidth:(float)menuWidth;
+- (id)initWithMenuWidth:(float)menuWidth numberOfFolds:(int)numberOfFolds;
+/**
+ * This method fold/unfolds to hide/reveal the menuTableView
+ * @param show A boolean value to indicate if the menu should be shown or hidden
+ * @param animated A boolean value to indicate if the folding/unfolding should be animated
+ */
+- (void)showMenu:(BOOL)show animated:(BOOL)animated;
@end
Oops, something went wrong.

0 comments on commit f14c253

Please sign in to comment.