From 7d8701c849d910c0e1b1c2a100084b2d8883e839 Mon Sep 17 00:00:00 2001 From: Aaron Brethorst Date: Sun, 4 Sep 2011 19:56:52 -0700 Subject: [PATCH] add rudimentary support for modal view controllers --- ABRouter/ABRouter.h | 1 + ABRouter/ABRouter.m | 8 ++ Example/View Controllers/RootViewController.h | 1 + Example/View Controllers/RootViewController.m | 5 ++ .../View Controllers/RootViewController.xib | 82 +++++++++++++++---- 5 files changed, 79 insertions(+), 18 deletions(-) diff --git a/ABRouter/ABRouter.h b/ABRouter/ABRouter.h index 07d2a0a..32de556 100644 --- a/ABRouter/ABRouter.h +++ b/ABRouter/ABRouter.h @@ -31,4 +31,5 @@ + (ABRouter*)sharedRouter; - (void)registerURLPattern:(NSString*)pattern forViewControllerClass:(Class)aClass; - (void)navigateTo:(NSString*)route withNavigationController:(UINavigationController*)navController; +- (void)modallyPresent:(NSString*)route from:(UIViewController*)viewController; @end \ No newline at end of file diff --git a/ABRouter/ABRouter.m b/ABRouter/ABRouter.m index dce6bc3..27088a1 100644 --- a/ABRouter/ABRouter.m +++ b/ABRouter/ABRouter.m @@ -73,6 +73,14 @@ - (void)registerURLPattern:(NSString*)pattern forViewControllerClass:(Class)aCla [routePatterns addObject:[NSDictionary dictionaryWithObjectsAndKeys:[SOCPattern patternWithString:pattern], kPatternKey, aClass, kViewControllerKey, nil]]; } +- (void)modallyPresent:(NSString*)route from:(UIViewController*)viewController +{ + UIViewController * pushMe = [self match:route]; + pushMe.apiPath = route; + UINavigationController *nav = [[[UINavigationController alloc] initWithRootViewController:pushMe] autorelease]; + [viewController presentModalViewController:nav animated:YES]; +} + - (void)navigateTo:(NSString*)route withNavigationController:(UINavigationController*)navController { UIViewController * pushMe = [self match:route]; diff --git a/Example/View Controllers/RootViewController.h b/Example/View Controllers/RootViewController.h index d472962..281d5e7 100644 --- a/Example/View Controllers/RootViewController.h +++ b/Example/View Controllers/RootViewController.h @@ -11,4 +11,5 @@ @interface RootViewController : UIViewController - (IBAction)viewAlbums:(id)sender; - (IBAction)viewPhotos:(id)sender; +- (IBAction)modal:(id)sender; @end diff --git a/Example/View Controllers/RootViewController.m b/Example/View Controllers/RootViewController.m index 1ac6bfe..12541b0 100644 --- a/Example/View Controllers/RootViewController.m +++ b/Example/View Controllers/RootViewController.m @@ -32,4 +32,9 @@ - (IBAction)viewPhotos:(id)sender [[ABRouter sharedRouter] navigateTo:@"/photos" withNavigationController:self.navigationController]; } +- (IBAction)modal:(id)sender +{ + [[ABRouter sharedRouter] modallyPresent:@"/photos" from:self]; +} + @end diff --git a/Example/View Controllers/RootViewController.xib b/Example/View Controllers/RootViewController.xib index 4d4b897..52808df 100644 --- a/Example/View Controllers/RootViewController.xib +++ b/Example/View Controllers/RootViewController.xib @@ -42,26 +42,26 @@ 274 YES - + 292 {{80, 48}, {160, 37}} - + _NS:222 NO IBCocoaTouchFramework 0 0 - + Helvetica-Bold 15 16 1 View some albums - + 3 MQA @@ -69,38 +69,60 @@ 1 MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA - + 3 MC41AA - + 292 {{80, 101}, {160, 37}} - + _NS:222 NO IBCocoaTouchFramework 0 0 - + 1 View some photos - + 1 MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA - + + + + + 292 + {{74, 178}, {173, 37}} + + + + _NS:222 + NO + IBCocoaTouchFramework + 0 + 0 + + 1 + How about a modal? + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + {{0, 20}, {320, 460}} - + 3 MQA @@ -126,7 +148,7 @@ viewAlbums: - + 7 @@ -135,12 +157,21 @@ viewPhotos: - + 7 7 + + + modal: + + + 7 + + 9 + @@ -156,8 +187,9 @@ YES - - + + + @@ -174,12 +206,17 @@ 4 - + 5 - + + + + + 8 + @@ -195,6 +232,7 @@ 1.IBPluginDependency 4.IBPluginDependency 5.IBPluginDependency + 8.IBPluginDependency YES @@ -205,6 +243,7 @@ com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -219,7 +258,7 @@ - 7 + 9 @@ -231,6 +270,7 @@ YES YES + modal: viewAlbums: viewPhotos: @@ -238,17 +278,23 @@ YES id id + id YES YES + modal: viewAlbums: viewPhotos: YES + + modal: + id + viewAlbums: id