在 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 {
但它不起作用。就好像找不到任何映射一样。这是为什么呢?我做错了什么?
更新:
这是根据建议更新的代码:
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
我在这里做错了什么?
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*)query
what am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有告诉它要调用哪个选择器!首先,在映射末尾添加
?
:@"tt://group?"当您添加任何查询字典时,它们会像 url 中的普通参数一样发送 (
?foo=bar&apple=orange
)。接下来,如果您不打算使用选择器作为 URL 映射的一部分,请使用
from:toSharedViewController:selector:
方法将选择器设置为您想要调用的选择器。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.我不太了解 Three20,但我认为您首先需要创建一个指向您想要传递的对象的 URL,该对象可以被映射。
看起来 Three20 在 nsobject 上提供了一个类别,允许您调用:
NSString* url = [myFooObject URLValueWithName:@"barName"];
几乎所有框架类都应该从 NSObject 继承该方法。
请参阅您发布的教程中URL 映射方法一章中的NSObjects 到 URL。
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.