2013-02-20 4 views
1

이미지 식별자를 받아들이고 AFNetworking의 AFImageRequestOperation을 사용하여 이미지를 다운로드하는 편리한 함수를 작성하려고합니다. 이 함수는 이미지를 제대로 다운로드하지만 성공 블록에서 UIImage를 반환 할 수 없습니다. 무슨 일이 일어나고 있는지의AFImageRequestOperation의 성공 블록에서 이미지를 반환

Incompatible block pointer types sending 'UIImage *(^)(NSURLRequest *__strong, NSHTTPURLResponse *__strong, UIImage *__strong)' to parameter of type 'void (^)(NSURLRequest *__strong, NSHTTPURLResponse *__strong, UIImage *__strong)' 

어떤 아이디어 :

-(UIImage *)downloadImage:(NSString*)imageIdentifier 
{ 
    NSString* urlString = [NSString stringWithFormat:@"http://myserver.com/images/%@", imageIdentifier]; 

    AFImageRequestOperation* operation = [AFImageRequestOperation imageRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] imageProcessingBlock:nil 
    success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) 
    { 
    NSLog(@"response: %@", response); 
    return image;             
    } 
    failure:nil]; 

[operation start]; 

} 

return image; 라인은 나에게 오류를 제공? 난 그냥 이미지 다운로드 작업이 비동기 AFNetworking

UIImage* photo = [downloadImage:id_12345];

답변

3

호출 할 수 싶어요, 당신은 운전 시작 시점을 할당 할 수 없습니다.

빌드하려는 함수는 대리자 또는 블록을 사용해야합니다. 이

// start updating download progress UI 
[serverInstance downloadImageWithCompletionBlock:^(UIImage *downloadedImage) { 
    myImage = downloadedImage; 
    // stop updating download progress UI 
} identifier:@""]; 
같은

- (void)downloadImageWithCompletionBlock:(void (^)(UIImage *downloadedImage))completionBlock identifier:(NSString *)identifier { 
    NSString* urlString = [NSString stringWithFormat:@"http://myserver.com/images/%@", identifier]; 

    AFImageRequestOperation* operation = [AFImageRequestOperation imageRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] imageProcessingBlock:nil 
    success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) 
    { 
    NSLog(@"response: %@", response); 
    completionBlock(image);             
    } 
    failure:nil]; 

    [operation start]; 
} 

전화를

관련 문제