【问题标题】:How to use NSObject to URLs with three20 properly如何正确使用 NSObject 到带有three20 的 URL
【发布时间】:2010-04-21 15:51:14
【问题描述】:

基本上我映射我的控制器以接受要传递到列表页控制器的地址类。在这里完成:

[map from:@"tt://listingPage/(initWithResult:)" toViewController:[ListingPageController class]];
[map from:[Address class] name:@"result" toURL:@"tt://listingPage/(initWithResult:)"];

此 url 正在我的表格项中使用,该表格项正在填充到数据源中:

for (Address *result in [(id<SearchResultsModel>)self.model results]) {
      NSString* url = [result URLValueWithName:@"result"];
      TTTableImageItem* tii = [TTTableMessageItem itemWithTitle:[result addressText] 
                                            caption:[result addressText]
                                            text:[result subText] 
                                            imageURL:[result image] 
                                            URL:url];
    [self.items addObject:tii];
}

我的应用程序崩溃了,我不知道为什么,似乎得到了一个无效的视图。任何帮助将非常感激。

【问题讨论】:

  • 您的地址对象是什么样的?这可能会有所帮助。

标签: objective-c iphone three20


【解决方案1】:

Three20 URL Based Navigation Guide

[map from:[Address class] name:@"result" toURL:@"tt://listingPage/(initWithResult:)"];

您遇到的问题是您的代码试图在 [Address class] 实例上调用方法 (initWithResult:)

您需要做的是从 Address 实例中检索 Result 参数并使用它来形成您的 URL。

例子:

@interface ListingPageController : UIViewController
    - (id)initWithResult:(NSNumber *)resultId;
@end

@interface Address : NSObject
    @property (nonatomic, copy) NSNumber *resultId;
@end

因此,在这种情况下,您需要将 resultIdAddress 传递给您的 initWithResult: 调用 ListPageController

[map from:[Address class] name:@"result" toURL:@"tt://listingPage/(resultId)"];   
[map from:@"tt://listingPage/(initWithResult:)" toViewController:[ListingPageController class]]; 

请注意,(resultId)- 中没有冒号,因为这是一个属性 getter 方法调用。

如下示例:

Address *result = [[[Address alloc] init] autorelease];
result.resultId = [NSNumber numberWithInt:12345];
NSString* url = [result URLValueWithName:@"result"];
[[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:url]];

这将首先将 result 转换为 URL tt://listingPage/12345,然后打开该 URL,该 URL 又调用 ListingPageController initWithResult:12345

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-26
    • 2020-09-30
    • 2017-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多