使用返回并获取参数的块

时间:2012-05-17 00:24:33

标签: iphone objective-c ios ipad block

所以在AFNetworking中有一个函数如下:

+ (AFImageRequestOperation *)imageRequestOperationWithRequest:(NSURLRequest *)urlRequest
                                         imageProcessingBlock:(UIImage *(^)(UIImage *))imageProcessingBlock
                                                    cacheName:(NSString *)cacheNameOrNil
                                                      success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success
                                                      failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure
{

我试图按如下方式使用它:

 [AFImageRequestOperation imageRequestOperationWithRequest:nil imageProcessingBlock:^UIImage * (UIImage *) {

        }cacheName:@"nsurl" success:^(NSURLRequest *request, NSHTTPURLResponse * response, UIImage * image){

        }failure:^(NSURLRequest *request, NSHTTPURLResponse * response, NSError * error){

        }];

然而,它在UIImage部分似乎不正确..任何想法?

1 个答案:

答案 0 :(得分:3)

你差不多了 - 你的代码缺少第一个区块中图像的参数名称:

[AFImageRequestOperation imageRequestOperationWithRequest:nil imageProcessingBlock:^UIImage * (UIImage *image) { // <<== HERE

} cacheName:@"nsurl" success:^(NSURLRequest *request, NSHTTPURLResponse * response, UIImage * image){

}failure:^(NSURLRequest *request, NSHTTPURLResponse * response, NSError * error){

}];

我认为这是Xcode中的一个错误,因为它将签名扩展为您发布的内容,而没有参数名称。