Restkit을 사용하여 웹 서버 api를 호출하려고하지만 상황이 작동하지 않습니다. 컨트롤러에 활동 표시기가 나타나고 아무 반응이 없습니다.RestKit with Three20 Integration
나는 예를 들어, 상위 50 비디오를 반환하는 가정 API 호출이 있습니다 http://example.com/services/getTop50Video
반환은의 형식에 :
<results>
<mysql_host>72.9.41.97</mysql_host>
<results>
<title/>
<views/>
<video_id>j2xFxHgENt4</video_id>
<thumbnail>http://img.youtube.com/vi/j2xFxHgENt4/2.jpg</thumbnail>
<url/>
</results>
...
</results>
내 앱의 대표 코드 :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Configure RestKit Object Manager
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:@"http://example.com/services"];
RKObjectMapper* mapper = objectManager.mapper;
[mapper registerClass:[YouTubeVideo class] forElementNamed:@"video"];
// Other non relevant stuff
}
TWYouTubeVideo 클래스 :
@implementation TWYouTubeVideo
@synthesize title = _title;
@synthesize numberOfViews = _numberOfViews;
@synthesize videoID = _videoID;
@synthesize thumbnailURL = _thumbnailURL;
+ (NSDictionary*)elementToPropertyMappings {
return [NSDictionary dictionaryWithKeysAndObjects:
@"title", @"title",
@"views", @"numberOfViews",
@"video_id", @"videoID",
@"thumbnail", @"thumbnailURL",
nil];
}
내 컨트롤러 코드 :
-(id) initWithResourcePath:(NSString*) requestedResourcePath
{
if (self = [super init])
{
self.resourcePath = requestedResourcePath;
}
return self;
}
- (void)createModel {
self.model = [[[RKRequestTTModel alloc] initWithResourcePath:self.resourcePath] autorelease];
}
- (void)didLoadModel:(BOOL)firstTime {
[super didLoadModel:firstTime];
RKRequestTTModel* model = (RKRequestTTModel*)self.model;
NSMutableArray* items = [NSMutableArray arrayWithCapacity:[model.objects count]];
for (YouTubeVideo* video in model.objects) {
TableSubtitleItem *item = [TableSubtitleItem itemWithText:video.title
subtitle:[NSString stringWithFormat:@"%@ views", video.numberOfViews]
imageURL:video.thumbnailURL
defaultImage:[YouTubeVideo defaultThumbnail]
URL:nil
accessoryURL:nil];
[items addObject:item];
}
// Ensure that the datasource's model is still the RKRequestTTModel;
// Otherwise isOutdated will not work.
TTListDataSource* dataSource = [TTListDataSource dataSourceWithItems:items];
dataSource.model = model;
self.dataSource = dataSource;
}
그리고 컨트롤러 밀어 :
SecondYouTubeController* viewController = [[SecondYouTubeController alloc] initWithResourcePath:@"/getTop50VideoXML?json=true"];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
첫째, 나는 어떻게 든 파서 말할 필요 같아요 비디오 객체는 "응답"노드 안에 나타납니다. 둘째, 나는 모든 전화를해야한다고 확신하지 못합니다.
정말 도움을 주시면 감사하겠습니다.
적어도 내 소스에는 RKRequestTTModel에 keyPath 속성이 없습니다. 다른 물건을 의미 했습니까? 그리고 네, XML에서 예제를 보여 줬지만 실제로 JSON 응답을 받았습니다. – Idan
아니요, 아니지만 거기에 대한 이니셜 라이저가 있습니다 : - (id) initWithResourcePath : (NSString *) resourcePath params : (NSDictionary *) params objectClass : (클래스) klass keyPath : (NSString *) keyPath; – Jerceratops
또는 접근자를 추가 할 수 있습니다. 모델을 뷰 컨트롤러 모델로 설정하기 전에 접근자를 설정했는지 확인하십시오. – Jerceratops