我希望你能帮助我解决这个问题。
我有一个表视图,单元格有一个图像,单元格的高度取决于图像。我使用SDWebImage来管理图像的下载。为了获得图像,我在cellForRowAtIndexPath中使用了这句话:
[cell.imageView func_crossdissolveFromURL:imageURL];
函数func_crossdissolveFromURL如下:
- (void)func_crossdissolveFromURL:(NSString *)urlString {
[self.activityIndicator stopAnimating];
[self.downloadOperation cancel];
if (!urlString) {
return;
}
UIImage *memImage = [[SDImageCache sharedImageCache] imageFromMemoryCacheForKey:urlString];
if (memImage) {
[self _crossdisolve:memImage cacheType:SDImageCacheTypeMemory];
return;
}
[self.activityIndicator startAnimating];
SDWebImageManager *manager = [SDWebImageManager sharedManager];
__weak UIImageView *wself = self;
id<SDWebImageOperation> operation = [manager downloadWithURL:[NSURL URLWithString:urlString]
options:SDWebImageAllowInvalidSSLCertificates
progress:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
[self.activityIndicator stopAnimating];
if (!wself) return;
dispatch_main_sync_safe(^{
if (!wself || !image) return;
[self _crossdisolve:image cacheType:cacheType];
});
}];
self.downloadOperation = operation;
}
调用_crossdissolve的函数接近结尾是这样的:
- (void)_crossdisolve:(UIImage *)image cacheType:(SDImageCacheType)cacheType {
CGFloat duration = (cacheType == SDImageCacheTypeMemory) ? 0 : 0.25f;
[UIView transitionWithView:self
duration:duration
options:UIViewAnimationOptionTransitionCrossDissolve
animations:^{
self.image = image;
}
completion:^(BOOL finished) {
[self setNeedsLayout];
}];
}
那么,我怎么能让每个单元格都具有内容图像的高度?提前谢谢。
答案 0 :(得分:1)
你需要两件事:
self.tableView.rowHeight = UITableViewAutomaticDimension;
要在显示单元格后更改单元格的高度,可以重新加载单元格。