TTNavigation传递数据

时间:2011-01-15 01:50:59

标签: iphone sdk three20

这个问题似乎很难解释,所以我会尽我所能。

我有几个用户个人资料。我希望他们全部由同一个班级处理。

TT://User/1
TT://User/2

如何将它们映射到为什么这些都推送到用户类。

除此之外,我如何告诉用户类要提取的用户ID。

2 个答案:

答案 0 :(得分:3)

首先,您需要将URL映射到控制器。您通常在AppDelegate中执行此操作,因为您希望在调用URL以显示视图之前设置URL映射。

  • 实例化TTNavigator
  • 通过TTURLMap将URL映射到控制器
  • 始终以通配符URL开头,即。 *并将其映射到默认视图控制器,如TTWebController(Web浏览器视图控制器)
  • 基本上,有两种类型的URL:1)没有参数的URL和2)URL w /参数。对于前者,当调用URL时,将调用映射视图控制器的initWithNibName:bundle:“constructor”。对于后者,您可以指示在TTURLMap中调用的“init”方法。见下面的例子。
  • 实际上通过openURLAction:method打开一个URL。

这是代码。

@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

其次,继承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

第三,从应用程序的任何位置导航到URL。

// Navigate to the URL.
[[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:@"tt://user/1"]];

答案 1 :(得分:1)