传递URL到Three20 TTURLMap [英] Passing url to Three20 TTURLMap
问题描述
我正在尝试将一个URL作为参数传递给TTURLMap,如下所示:
[map from @ tt:// person /(initWithURL :)toViewController:
[PersonViewController class]];
然后我有一个TTStyledTableItemCell,其链接呈现如下:
< a href =tt:// person / http://persons.url.com/blah>个人名称< / a>
p>
但是当我点击这些链接时,链接不会调用PersonViewConroller类中的initWithURL:
方法。我已经验证的东西是
通过传递一个简单的字符串正确连接。我相信这个
不工作,因为解析器认为URL是
TTURLMap url映射的一部分。有没有办法逃避该人的饲料网址
(我需要使用的休息服务来提取信息)?
提前多谢。
我认为TTURLMap唯一出现的角色是 /
字符,所以以下为我做的伎俩。只要打电话给Mike,在你的初始化函数中进入和退出
+(NSString *)encodeTtUrl:(NSString * )str {
NSMutableString * temp = [NSMutableString stringWithString:str];
[temp replaceOccurrencesOfString:@/withString:@__options:NSLiteralSearch range:NSMakeRange(0,[temp length])];
return [NSString stringWithString:temp];
}
+(NSString *)decodeTtUrl:(NSString *)str {
NSMutableString * temp = [NSMutableString stringWithString:str];
[temp replaceOccurrencesOfString:@__withString:@/options:NSLiteralSearch range:NSMakeRange(0,[temp length])];
return [NSString stringWithString:temp];
}
I am trying to pass in a URL as a parameter to a TTURLMap like this:
[map from@"tt://person/(initWithURL:)" toViewController:
[PersonViewController class]];
I then have a TTStyledTableItemCell with links that render like this:
<a href="tt://person/http://persons.url.com/blah">Person name</a>
but when I click on these links the link doesn't call the initWithURL: method in the PersonViewConroller class. I've verified things are wired up correctly by passing in a simple string. I believe this isn't working because the parser thinks the URL is part of the TTURLMap url mapping. Is there a way to escape the person's feed url (its a rest service that i need to use to pull info in)?
many thanks in advance.
I think the only character that TTURLMap trips up on is the /
character, so the following did the trick for me. Just call these as Mike suggests on the way in and out of your init function
+ (NSString *)encodeTtUrl:(NSString *)str {
NSMutableString *temp = [NSMutableString stringWithString:str];
[temp replaceOccurrencesOfString:@"/" withString:@"__" options:NSLiteralSearch range:NSMakeRange(0, [temp length])];
return [NSString stringWithString:temp];
}
+ (NSString *)decodeTtUrl:(NSString *)str {
NSMutableString *temp = [NSMutableString stringWithString:str];
[temp replaceOccurrencesOfString:@"__" withString:@"/" options:NSLiteralSearch range:NSMakeRange(0, [temp length])];
return [NSString stringWithString:temp];
}
这篇关于传递URL到Three20 TTURLMap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!