Passing url to Three20 TTURLMap

≯℡__Kan透↙ 提交于 2019-12-04 19:28:07

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

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.)

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