Multi-parameter mapping with Three20 and 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]];
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开发者_JS百科, 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?
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
精彩评论