2011-07-15 47 views
0

我正在关注教程here在URL中传递本地对象

我的代码是:

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

} 

我已经设置映射为:

[map from:@"tt://group" toSharedViewController:[TopicsViewController class]]; 

和我TopicsViewController内我都试过:

- (id) initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query { 

但它没没有工作。就好像它找不到任何映射。为什么是这样?我究竟做错了什么?

UPDATE:

这里的基础上,建议更新的代码:

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*)query 

我究竟错在这里做什么?

回答

1

你不是在告诉它什么选择器来校准!首先,在映射的末尾添加一个?:@“tt:// group?”

当您添加任何查询词典时,它们会像url中的正常参数一样发送(?foo=bar&apple=orange)。

接下来,如果您不打算将选择器用作URL映射的一部分,请使用from:toSharedViewController:selector:方法将选择器设置为您希望调用的选择器。

+0

我其实只是想要它调用initWithNavigatorURL:(NSURL *)URL查询:(NSDictionary *)查询,而不是另一个选择器...看到一些其他的例子,似乎没有人使用它? ..你能否详细说明。即使在上面的问题中我链接的three20文档..它没有使用? – adit

+0

为什么你在init方法中关心navigatorURL?你为什么需要它?无论哪种方式,将您的选择器设置为@selector(initWithNavigatorURL :)。 – coneybeare

+0

我实际上并不关心navigatorURL,我只关心被传入的对象..无论如何,我尝试了你的建议,但它仍然不起作用... – adit

0

我不太了解three20,不过我想你首先需要创建一个你想传递的对象的URL,它可以被映射。

它看起来像three20提供NSObject的一个类别,它允许您拨打:
NSString* url = [myFooObject URLValueWithName:@"barName"];

此方法应该从NSObject的几乎任何一个框架类继承。

NSObjects到URL从您发布的教程章节URL映射方法

+0

据我所知......当我们传递一个对象作为参数时,你不会设置该对象的URL ..如果你设置了对象的URL,那么URL在我的情况下会是什么样子? – adit