[英]How to use NSObject to URLs with three20 properly
基本上,我映射我的控制器以接受要傳遞到listingpage控制器中的地址類。 在這里完成:
[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];
}
我不確定為什么我的應用程序崩潰了,但似乎無法獲取視圖。 任何幫助將非常感激。
[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
因此,在這種情況下,您想將Address
的resultId
傳遞給ListPageController
上的initWithResult:
調用。
[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
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.