iphone - 使用返回并接受参数的 block
<p><p>所以在AFNetworking中有一个函数如下:</p>
<pre><code>+ (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
{
</code></pre>
<p>我正在尝试按如下方式使用它:</p>
<pre><code> [AFImageRequestOperation imageRequestOperationWithRequest:nil imageProcessingBlock:^UIImage * (UIImage *) {
}cacheName:@"nsurl" success:^(NSURLRequest *request, NSHTTPURLResponse * response, UIImage * image){
}failure:^(NSURLRequest *request, NSHTTPURLResponse * response, NSError * error){
}];
</code></pre>
<p>但是 UIImage 部分似乎不正确.. 有什么想法吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您快到了 - 您的代码在第一个 block 中缺少图像的参数名称:</p>
<pre><code>[AFImageRequestOperation imageRequestOperationWithRequest:nil imageProcessingBlock:^UIImage * (UIImage *image) { // <<== HERE
} cacheName:@"nsurl" success:^(NSURLRequest *request, NSHTTPURLResponse * response, UIImage * image){
}failure:^(NSURLRequest *request, NSHTTPURLResponse * response, NSError * error){
}];
</code></pre>
<p>我认为这是 Xcode 中的一个错误,因为它将签名扩展为您发布的内容,没有参数名称。</p></p>
<p style="font-size: 20px;">关于iphone - 使用返回并接受参数的 block ,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/10628447/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/10628447/
</a>
</p>
页:
[1]