2

i would like to know that after passing object from view to view with URL, how to i pass it to the model so i can use it for web service and populate the datasource.

Using Three20 (: Thanks.

Sydnal
  • 23
  • 2

1 Answers1

4

Copied from: http://three20.info/article/2010-10-06-URL-Based-Navigation

Original Author: Jeff Verkoeyen

One of the first questions people ask about TTNavigator is how to pass native objects around, rather than encoding them somehow in a URL. There is a simple pattern for this, using the query property of TTURLAction (or its equivalent convenience function, applyQuery:). For example, imagine you wanted to pass along an NSArray of items to show in the new view:

NSArray *arr = [...load up with data...];
[[TTNavigator navigator] openURLAction:[[TTURLAction actionWithURLPath:@"tt://restaurant/Chotchkie's"]
  applyQuery:[NSDictionary dictionaryWithObject:arr forKey:@"arrayData"]]];

In this example, the array is passed directly to the initWithName: but only if there is a matching selector that accepts the query:

-(id) initWithName: (NSString*)name query:(NSDictionary*)query {
  for (MyObject* item in [query objectForKey:@"arrayData"])
    //... do something with item ...
  }

  // ...
}
tonklon
  • 6,777
  • 2
  • 30
  • 36
  • 1
    i'll also add the way you create default initializer: `- (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query`, so you can pass no params in url, but some in query – Michał Zygar Jul 15 '11 at 08:02