【问题标题】:pass native object in URL在 URL 中传递本机对象
【发布时间】:2011-07-15 06:13:16
【问题描述】:

我正在关注教程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 

我在这里做错了什么?

【问题讨论】:

    标签: iphone objective-c ipad three20


    【解决方案1】:

    你没有告诉它要调用什么选择器!首先,在映射末尾添加?:@"tt://group?"

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

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

    【讨论】:

    • 我实际上只是希望它调用 initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query,而不是另一个选择器......看到其他一些例子,似乎没有人使用它? ..你能详细说明一下吗?即使在我在上述问题上链接的three20文档中..它也没有使用?
    • 为什么要关心 init 方法中的 navigatorURL?你为什么需要它?无论哪种方式,将您的选择器设置为 @selector(initWithNavigatorURL:)。
    • 我其实并不关心navigatorURL,我只关心对象是否被传递。无论如何我尝试了你的建议,它仍然不起作用......
    • 您在选择器中缺少“:”,而 ?进入映射,而不是动作
    • 您的方法名称错误。您的选择器是 initWithNavigatorURL,而不是 ...NavigationURL
    【解决方案2】:

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

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

    几乎所有框架类都应该从 NSObject 继承此方法。

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

    【讨论】:

    • 据我所知...当我们将对象作为参数传递时,您没有设置对象的 URL。如果您设置对象的 URL,那么 URL 是什么看起来像我的情况?
    猜你喜欢
    • 2022-01-23
    • 2018-04-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-09
    • 1970-01-01
    • 1970-01-01
    • 2021-03-05
    相关资源
    最近更新 更多