First, you need to map URLs to controllers. You typically do this in the AppDelegate since you want to have the URL map set up before calling a URL to display a view.
- Instantiate a TTNavigator
- Map the URLs to the controllers via TTURLMap
- Always start with a wildcard URL ie. * and map it to a default view controller like TTWebController (the web browser view controller)
- Basically, there are 2 types of URL: 1) URL without parameters and 2) URL w/ parameters. For the former, when URL is invoked, the initWithNibName:bundle: "constructor" of the mapped view controller will be called. For the latter, you can indicate what "init" method to call in the TTURLMap. See example below.
- Actually opens an URL via openURLAction: method.
Here's the code.
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(UIApplication *)application {
TTNavigator* navigator = [TTNavigator navigator];
TTURLMap* map = navigator.URLMap;
// This is the default map. * = wildcard, any URL not registered will be
// routed to the TTWebController object at runtime.
[map from:@"*" toViewController:[TTWebController class]];
[map from:@"tt://catalog" toViewController:[CatalogController class]];
[map from:@"tt://user/(initWithId:)"
toViewController:[MyUserViewController class]];
[map from:@"tt://user/(initWithId:)"
toViewController:[MyUserViewController class]];
if (![navigator restoreViewControllers]) {
[navigator openURLAction:[TTURLAction actionWithURLPath:@"tt://catalog"]];
}
}
// ...
@end
Second, subclass a TTViewController
@implementation MyUserViewController
- (id) initWithId:(NSNumber *)index {
if (self = [super initWithNibName:nibName bundle:nil]) {
// Do your initialization here.
// Get the index from a singleton data manager containing the "model."
}
return self;
}
@end
Third, navigate to the URL from anywhere in the app.
// Navigate to the URL.
[[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:@"tt://user/1"]];