Alex Rivera | Logout

understanding TTNavigator

Asked 2010-02-23T11:42:09.120
9

following situation:

in a TTTableViewController i added some Cells with URLs. they are opening a class with @"tt://photos" for example. this works quite fine.

the first thing is, i saw some urls in TT Examples like @"tt/photos/1". is it possible to fetch this "1" in my photos class and say, for example okay, please open picture one, ore is this only another URL that was declared in TTNavigatior to open a specific Class?

the other thing is: is it possible to forward an object to the linked class? clicking a cell opens @"tt://photos" (the linked class in my TTNavigator)

working with normal tableviews i can overwrite my init method and send an object with my initialize method, is this also possible by clicking my TTItems?

thanks!

Edit
Report

2 Answers

21

figured it out myself, for those who need it:

First (passing "subURLs" in your navigator map)

navigating to an URL with @"tt://photos/firstphoto" is possible, you can fetch the "firstphoto" like this:

//Prepare your Navigator Map like this
[map from:@"tt://photos/(initWithNumber:)" toViewController:[PhotoVC class]];

In your PhotoVC you can access this Number:

-(void) initWithNumber: (NSString*)number {
    NSLog(@"%@",number);
}

calling your View Controller with this url would look:

PhotoVC* controller = [[PhotoVC alloc] initWithNumber:@"1"];
[navigationController pushViewController:controller animated:YES];
[controller release];

Second (passing objects in an TTTableViewController)

its a bit tricky, but you dont have to Subclass anything.

first, nil the URL in the TableItem

 [TTTableLink itemWithText:@"TTTableLink" URL:nil]

in your TTTableViewController write down this method

- (void)didSelectObject:(id)object atIndexPath:(NSIndexPath*)indexPath {
     TTURLAction *urlAction = [[[TTURLAction alloc] initWithURLPath:@"tt://photos"] autorelease];
     urlAction.query = [NSDictionary dictionaryWithObject:@"firstphoto" forKey:@"photo"];
     urlAction.animated = YES;
     [[TTNavigator navigator] openURLAction:urlAction];
 }

now in your your PhotoVC you need something like this

- (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query {
     if (self = [super init]) {
              NSLog(@"%@",query);
}

     return self;
}

and you are done ;)

answered 2010-02-23T18:46:05.423
0

Although choice's answer works for multiple params when u are creating the TTURLAction in code it is not very useful when u want to embed links to view controllers in your TTStyledLabel.One solution to that is to use multiple params in a single string.

<a href='app://view2/param1=value1&param2=value2&...'>LabelName</a>

if you want the code to parse such urls and get the params please feel free to send me a message and I will send you my parser classes. (or you can build your own with NSScanner!)

Also dont forget to escape the &s otherwise TTStyledLabel would not like it!

answered 2011-05-17T21:08:56.290

Your Answer