我試圖等待使用Restkit with Blocks的響應。iOS RestKit塊
例子:
NSArray *myArray = ["RESULT OF REST-REQUEST"];
// Working with the array here.
我的一個塊的請求:
- (UIImage*)getPhotoWithID:(NSString*)photoID style:(NSString*)style authToken:(NSString*)authToken {
__block UIImage *image;
NSDictionary *parameter = [NSDictionary dictionaryWithKeysAndObjects:@"auth_token", authToken, nil];
RKURL *url = [RKURL URLWithBaseURLString:@"urlBase" resourcePath:@"resourcePath" queryParameters:parameter];
NSLog(@"%@", [url absoluteString]);
[[RKClient sharedClient] get:[url absoluteString] usingBlock:^(RKRequest *request) {
request.onDidLoadResponse = ^(RKResponse *response) {
NSLog(@"Response: %@", [response bodyAsString]);
image = [UIImage imageWithData:[response body]];
};
}];
return image;
}
你的問題是什麼? – Till 2012-07-17 08:39:07
該數組將爲null,因爲該方法在響應到達之前達到結束......我該如何「等待」響應。我認爲這將與塊 – Maik639 2012-07-17 10:03:40