pass native object in URL
I was following the tutorial here.
The code I have is:
- (void) didSelectObject:(id) object atIndexPath:(NSIndexPath*) indexPath
{
Group * group = (Group *)((RKMappableObjectTableItem *) object).object;
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
group.unread = 0;
[self.tableView reloadData];
TTURLAction *action = [[[TTURLAction actionWithURLPath:@"tt://group"]
applyQuery:[NSDictionary dictionaryWithObject:group forKey:@"kParameterUser"]]
applyAnimated:YES];
[[TTNavigator navigator] openURLAction:action];
}
I have set the mapping as:
[map from:@"tt://group" toSharedViewController:[TopicsViewController class]];
and inside my TopicsViewController I have both tried:
- (id) initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query {
but it didn't work. It's as if it can't find any mapping. Why is this? What am I doing wrong?
UPDATE:
Here's the updated code based on the suggestion:
TTURLAction *action = [[[TTURLAction actionWithURLPath:@"tt://group"]
applyQuery:[NSDictionary dictionaryWithObject:group forKey:@"kParameterUser"]]
applyAnimated:YES];
[[TTNavigator navigator] openURLAction:action];
[map from:@"tt://group?" toSharedViewController:[TopicsViewController class] selector:@selector(initWithNavigationURL:)];
- (id) initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)qu开发者_运维百科ery
what am I doing wrong here?
You are not telling it what selector to cal! First, add a ?
to the end of your mapping: @"tt://group?"
When you add any query dictionaries, they are sent like normal params in a url (?foo=bar&apple=orange
).
Next, if you aren't going to use the selector as part of the URL mapping, use the from:toSharedViewController:selector:
method to set the selector to the selector you wish to call.
I don't know three20 very well, I think however you first need to create an URL to the object you'd like to pass, which can be mapped.
It appears like three20 provides a category on nsobject which allows you to call:
NSString* url = [myFooObject URLValueWithName:@"barName"];
This method should be inherited from NSObject by almost any Framework Class.
See NSObjects to URLs in the chapter URL mapping methods from the tutorial you posted.
精彩评论