Multi-parameter mapping with Three20 and TTURLMap

2019-04-13 06:13发布

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

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.

Using single parameter, i.e something like x://profile/(initWithId:) does the right thing, which is to call [[ProfileViewController alloc] initWithId:1].

Did I miss something here? How to use multi-parameter mapping with Three20 and TTURLMap?

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-04-13 06:24

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

enjoy!

/mtr

查看更多
登录 后发表回答