在URL中传递本机对象

时间:2011-07-15 06:13:16

标签: iphone objective-c ipad three20

我正在关注教程here

我的代码是:

- (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 {

但它不起作用。好像它找不到任何映射。为什么是这样?我做错了什么?

更新

以下是基于建议的更新代码:

 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 

我在这里做错了什么?

2 个答案:

答案 0 :(得分:1)

你没有告诉它cal的选择器!首先,在映射的末尾添加?:@“tt:// group?”

当您添加任何查询字典时,它们会像网址(?foo=bar&apple=orange)中的普通参数一样发送。

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

答案 1 :(得分:0)

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

似乎three20在nsobject上提供了一个类别,允许你调用:
NSString* url = [myFooObject URLValueWithName:@"barName"];

这个方法几乎可以由任何Framework类从NSObject继承。

请参阅您发布的教程中 URL映射方法一章中的 NSObjects to URL