这是我的问题:
我有一个包含自定义UITableView
的{{1}}。每个UITableViewCell
(称为UITableViewCell
)都与HomePicCell
对象相关联,该对象具有指向图像URL的属性。
显示我的单元格后,我开始使用Pic
下载此图像。
一切顺利,但在20到80秒后,一些线程开始占用CPU 。然后该装置成为那些寒冷的冬夜的完美手部加热器,但我现在宁愿跳过这个功能!
我无法真正理解会导致此问题的原因。我不认为保留循环会成为问题,因为它只会占用内存。实验意见确实会有所帮助。
这是我的代码:
UITableView数据源
SDWebImage manager
HomePicCell(configureWithPic:)
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString* cellIdentifier = [@"HomePicCell" stringByAppendingString:[Theme sharedTheme].currentTheme];
HomePicCell* cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (!cell) {
cell = [[HomePicCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
if(self.pics.count>0){
Pic* pic = self.pics[indexPath.section];
[cell configureWithPic:pic];
}
return cell;
}
产品图
- (void)configureWithPic:(Pic*)pic
{
self.pic = pic;
// Reinit UI
[self.progressView setHidden:NO];
[self.errorLabel setHidden:YES];
[self.photoImageView setAlpha:0];
[self.progressView setProgress:0];
[self.pic downloadWithDelegate:self];
}
HomePicCell(委托方法)
- (void) downloadWithDelegate:(id<PicDownloadDelegate>)delegate
{
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:self.url options:0 progress:^(NSUInteger receivedSize, long long expectedSize) {
if(expectedSize>0){
float progress = [@(receivedSize) floatValue]/[@(expectedSize) floatValue];
[delegate pic:self DownloadDidProgress:progress];
}
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
self.isGif = @(image.images.count>1);
if(image){
if(cacheType == SDImageCacheTypeNone){
[delegate pic:self DownloadDidFinish:image fromCache:NO];
}else{
[delegate pic:self DownloadDidFinish:image fromCache:YES];
}
}else{
[delegate pic:self DownloadFailWithError:error];
}
}];
}
谢谢!
答案 0 :(得分:1)
通过切换到SDWebImage 3.0(而不是3.3),显然解决了这个问题。 我将继续在项目github页面上声明一个问题,看看是否有人遇到了同样的问题。