tags:

views:

757

answers:

1

Hi, How would I make the TTNavigator sample code to make one of the tabs go straight to a web view or straight to a youtube video etc? Here is the current code http://pastie.org/626186

+2  A: 

First, the class that you can use to control the dispatching of URLs in your application is TTURLMap. You can see how it's already set up in TTNavigatorDemo's AppDelegate.m file.

The trick here is that you can use wildcards when you set up your TTURLMap. By setting a "*" wildcard to a controller class, you're essentially telling your TTURLMap to dispatch all otherwise unmatched requests to a new instance of whatever controller class you pass it (in your case TTWebController)


TTURLMap* map = navigator.URLMap;
[map from:@"*" toViewController:[TTWebController class]];
[map from:@"tt://someController" toViewController:[SomeController class]];
...
if (![navigator restoreViewControllers]) {
  [navigator openURL:@"tt://someController" animated:NO];
}

I just checked TTNavigatorDemo, and it looks like this is actually already set up:


// Any URL that doesn't match will fall back on this one, and open in the web browser
  [map from:@"*" toViewController:[TTWebController class]];

Therefore, in your gist, you should be able to visit an arbitrary URL with the web view controller already, adding a line to your data source like this. Tapping this should push a new TTWebController with Google:


 [TTTableTextItem itemWithText:@"Google" URL:@"http://google.com"],

Further Reading: The NavigatorDemo does some really cool stuff. Someone from the Three20 Google Group published their notes when they were unpacking everything that's going on in the TTURLMap setup.

Justin Searls