使用Three20和TTURLMap进行多参数映射 [英] Multi-parameter mapping with Three20 and TTURLMap

查看:53
本文介绍了使用Three20和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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆