使用Three20和TTURLMap进行多参数映射 [英] Multi-parameter mapping with Three20 and TTURLMap
问题描述
我正在关注本教程,并在我的应用程序委托中声明以下映射:
I'm following this tutorial and declare the following mappings in my app delegate:
[map from:@"x://profile/(initWithId:)/(name:)" toViewController:[ProfileViewController class]];
[map from:@"*" toViewController:[TTWebController class]];
在ProfileViewController.m
中,我实现了- (id)initWithId:(int)anIdentifier name:(NSString *)name
选择器来处理这种映射.我想打开x://profile/1/John Doe
之类的URL会调用[[ProfileViewController alloc] initWithId:1 name:@"John Doe"]
,但是,事实并非如此.每次我打开所说的URL都会调用默认的TTWebController
类.
In ProfileViewController.m
I implement the - (id)initWithId:(int)anIdentifier name:(NSString *)name
selector to handle such mapping. I suppose opening URLs like x://profile/1/John Doe
would invoke [[ProfileViewController alloc] initWithId:1 name:@"John Doe"]
, however, this seems not to be the case. The default TTWebController
class gets called every time I open said URL.
使用单个参数,即x://profile/(initWithId:)
之类的东西做对了,那就是调用[[ProfileViewController alloc] initWithId:1]
.
Using single parameter, i.e something like x://profile/(initWithId:)
does the right thing, which is to call [[ProfileViewController alloc] initWithId:1]
.
我在这里错过了什么吗?如何在Three20和TTURLMap中使用多参数映射?
Did I miss something here? How to use multi-parameter mapping with Three20 and TTURLMap?
推荐答案
问题是"x://profile/1/John Doe"未正确设置为URL格式.构建网址时,请尝试以下操作:
the problem is the that "x://profile/1/John Doe" isn't properly formatted as a URL. when you build the URL, try something like:
NSString *URL = [NSString stringWithFormat:@"x://profile/%d/%@", 1,
[@".." stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
享受!
/mtr
这篇关于使用Three20和TTURLMap进行多参数映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!