如何正确使用NSObject到URL的对象
问题描述:
基本上我将我的控制器映射为接受要传递到listingpage控制器的地址类。这是在这里完成:如何正确使用NSObject到URL的对象
[map from:@"tt://listingPage/(initWithResult:)" toViewController:[ListingPageController class]];
[map from:[Address class] name:@"result" toURL:@"tt://listingPage/(initWithResult:)"];
该网址与正在被填充数据源中我的表项用于:
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];
}
我的应用程序崩溃,我不知道为什么,似乎越来越一个无效的视图。任何帮助将非常感激。
答
Three20 URL Based Navigation Guide
[map from:[Address class] name:@"result" toURL:@"tt://listingPage/(initWithResult:)"];
你的问题是,你的代码试图调用该方法(initWithResult:)
上[Address class]
实例。
你需要做的,而不是什么是检索来自Address
实例Result
参数,并用它来形成你的URL。
例子:
@interface ListingPageController : UIViewController
- (id)initWithResult:(NSNumber *)resultId;
@end
@interface Address : NSObject
@property (nonatomic, copy) NSNumber *resultId;
@end
因此,在这种情况下,你会想从Address
通过resultId
您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这将依次调用ListingPageController initWithResult:12345
。
你的Address对象是什么样的?这可能有帮助。 – changelog 2010-10-21 13:25:46