Skip to content
daltoniam edited this page Dec 3, 2012 · 1 revision

GPNav

GPNav is a simple way to create URL based navigation in your iOS app. It is basically designed to work like rails routes and make navigation simpler. It is highly integrated into GPLib for easy of use, but is not required to use GPLib.

How to start using (basic usage):

#import "testViewController.h"
#import "modaltest.h"
#import "ImageViewer.h"
#import "LauncherViewController.h"
#import "GridViewController.h"
#import "ListViewController.h"
#import "GPTabBarController.h"
#import "ImageFilterViewController.h"
#import "TableViewController.h"
#import "CalendarViewController.h"

@implementation AppDelegate

@synthesize window = _window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
	//map your view controllers to there respective URLs
    [[GPNavigator navigator] mapViewController:[modaltest class] toURL:@"gp://main"];
    [[GPNavigator navigator] mapViewController:[testViewController class] toURL:@"gp://test"];
    [[GPNavigator navigator] mapViewController:[testViewController class] toURL:@"gp://test/initWithCustom:"];
    [[GPNavigator navigator] mapViewController:[ImageViewer class] toURL:@"gp://imageview"];
    [[GPNavigator navigator] mapViewController:[LauncherViewController class] toURL:@"gp://launcher"];
    [[GPNavigator navigator] mapViewController:[GridViewController class] toURL:@"gp://gridview"];
    [[GPNavigator navigator] mapViewController:[ListViewController class] toURL:@"gp://list"];
    [[GPNavigator navigator] mapViewController:[TableViewController class] toURL:@"gp://table"];
    [[GPNavigator navigator] mapViewController:[CalendarViewController class] toURL:@"gp://calendar"];

    [[GPNavigator navigator] openURL:@"tt://table"]; //open the first view controller on the navigation stack
    self.window.rootViewController = [GPNavigator navigator].navigationController; 
    [self.window makeKeyAndVisible];
    return YES;
}

GPNavigator Properties and methods

enum GPNavType

Set the type of navigation you want to use, picking between different modal styles and popover.

@property(nonatomic, readonly, retain)UINavigationController* navigationController

the main UINavigationController used for navigation.

@property(nonatomic, readonly)UIViewController*visibleViewController

the currently visible view controller.

@property(nonatomic, readonly)NSMutableDictionary* URLs

the Dictionary of url to class mappings.

@property(nonatomic, assign)BOOL useCustomBackButton

set if you want to use a custom GPBarButtonItem as the back button. Default is NO.

@property(nonatomic, assign)BOOL searchAppStore

set if you want to search the app store for an unknown URL. Default is NO.

@property(nonatomic, retain)UIPopoverController* popOver

the UIPopoverController that is nil. Is set once a controller of this type is opened

+(GPNavigator*)navigator

Returns the shared instance of GPNavigator to be use for URL navigation.

-(SEL)selectorFromURL:(NSString*)URLstring

Returns a selector from the URL passed in. You should not really have a need to call this.

-(void)mapViewController:(Class)ViewClass toURL:(NSString*)URL

maps a viewController class to a URL string.

-(void)mapViewController:(Class)ViewClass toURL:(NSString*)URL

maps a viewController class to a URL string.

-(void)openURL:(NSString*)URL NavType:(GPNavType)type query:(NSDictionary*)query rightbtn:(UIBarButtonItem*)right leftbtn:(UIBarButtonItem*)left frame:(CGRect)frame view:(UIView*)gridView

the openURL opens a url passed in. NavType is the navigation type to use. Query is if you are passing a NSDictionary as a parameter to the class. left and right button are to set the navigation buttons when displaying modal, and to pick which button to open for in a popover. Frame is the frame to use in a gridview and popover. Gridview is a gridview to be opened. Most of this parameters you do not need to set and are used by the different parts of GPLib (gridView, tableView, etc). The main one you will call is either: openURL:(NSString*)URL and openURL:(NSString*)URL NavType:(GPNavType)type query:(NSDictionary*)query.

-(id)createViewControllerFromURL:(NSString*)URL type:(GPNavType)type query:(NSDictionary*)query

raw version of viewControllerFromURL used. Use viewControllerFromURL instead.

-(void)dismissModal;

Does the correct dismissal of popover and modal.

-(void)popNavigation;

pops the navigationController back. Equivalent of hitting the back button.

-(void)dismissGridView:(UIView*)view;

Dismiss gridView navigation type.

-(UIViewController*)viewControllerFromURL:(NSString*)URL query:(NSDictionary*)query

creates a viewController from the URL.

-(UIViewController*)GPRevealNavigation:(NSString*)URL;

Must use this when setting Rootviewcontroller if GPRevealNavigation is being used.

-(void)navigationControllerChange:(UINavigationController*)navBar

sets the navigationController property to a new instance of UINavigationController if needed.

-(UISplitViewController*)splitController:(NSString*)leftURL right:(NSString*)rightURL

creates an IPad only UISplitViewController off two URLs.