Strongly in this block is likely to lead to a retain cycle [duplicate]

流过昼夜 提交于 2020-05-01 07:23:27

问题


I create the custom cell with the activity indicator view With using the SDWebImage I hidden the activity indicator when the image is downloaded

[customCell.userPhotoImageView setImageWithURL:[NSURL URLWithString:[[thisNotify user]imageURL]] placeholderImage:nil completed:^
 (UIImage *image, NSError *error, SDImageCacheType cacheType)
 {
     customCell.activityView.hidden = TRUE;
 }];

But I execute the code I look this warning

Capturing 'customCell' strongly in this block is likely to lead to a retain cycle

Thanks


回答1:


You can try something like this just before that block call:

__weak UICustomCell * weakCustomCell = customCell;
[customCell.userPhotoImageView setImageWithURL:....^{
   weakCustomCell.activityView.hidden = YES;
}];

I think that will fix the error. You just assign a new weakly referenced object to your cell, which should prevent the retain cycle. Not entirely sure of the reasoning behind it, but worth a shot.

edit here's a potential explanation though



来源:https://stackoverflow.com/questions/27335587/strongly-in-this-block-is-likely-to-lead-to-a-retain-cycle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!