这个问题似乎很难解释,所以我会尽我所能。
我有几个用户个人资料。我希望他们全部由同一个班级处理。
TT://User/1
TT://User/2
如何将它们映射到为什么这些都推送到用户类。
除此之外,我如何告诉用户类要提取的用户ID。
答案 0 :(得分:3)
首先,您需要将URL映射到控制器。您通常在AppDelegate中执行此操作,因为您希望在调用URL以显示视图之前设置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)