我有以下代码来下载图像:
imageRequest = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:magazineItem.contentURL]];
__weak ASIHTTPRequest *weakRequest = imageRequest;
__block typeof (self) bself = self;
[imageRequest setCompletionBlock:^{
if (weakRequest.responseStatusCode == 200) {
bself.imageData = weakRequest.responseData;
[[DataAccessLayer sharedInstance] storeTemporaryContentData:bself.imageData url:magazineItem.contentURL];
bself.contentImage = [UIImage imageWithData:bself.imageData];
if (bself.contentImage != nil) {
if (bself.magazineItem.presentationStyle.intValue != -1) {
[bself setPresentationStyle:bself.magazineItem.presentationStyle.intValue];
}
else {
[bself setPresentationStyleForImage:bself.contentImage];
}
}
else
[bself.delegate contentItemViewUnavailable:bself];
}
else {
[bself.delegate contentItemViewUnavailable:bself];
}
}];
[imageRequest setFailedBlock:^{
if (weakRequest.error.code == 4)
return;
[bself.delegate contentItemViewUnavailable:bself];
}];
[imageRequest startAsynchronous];
尽管我使用__block typeof (self)
标识符将 self 传递到块中,但它仍然被保留。我也尝试过__weak MyClassName *bself = self;
,它仍然进入保留周期。看来我在这里遗漏了一些东西,谁能告诉我我到底做错了什么?
供参考imageRequest
的是我的 .m 文件类别中的 __strong iVar。
提前致谢。