Passing url to Three20 TTURLMap

岁酱吖の 提交于 2019-12-21 23:12:10

问题


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.


回答1:


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];
}



回答2:


This is a common problem. I haven't found an elegant solution; the best I've been able to find is to manually escape the URL on the way in (e.g. by Base64-encoding it), and then manually unescape it inside your initWithURL: function. (Actually, you'd probably want to have a function called initWithBase64EncodedURL: or something like that, for clarity.)



来源:https://stackoverflow.com/questions/3807979/passing-url-to-three20-tturlmap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!