开发者

Three20 Passing of Object

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 (: Th开发者_如何学Canks.


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 ...
  }

  // ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜