我使用下面的代码将图像缩放到我的UIImageView。当表第一次加载时,一切都很好。但是当我滚动桌面视图时,所有图像方面都被打破了。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ProductCell" forIndexPath:indexPath];
[self configureCustomCell:(ProductsTableViewCell*)cell atIndexPath:indexPath];
return cell;
}
- (void)configureCustomCell:(ProductsTableViewCell*)cell atIndexPath:(NSIndexPath *)indexPath {
NSURL *url = [NSURL URLWithString:[[arr_products objectAtIndex:indexPath.section] productImage]];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
__weak UITableViewCell *weakCell = cell;
[cell.productPhotoImage setImageWithURLRequest:request placeholderImage:nil
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) {
weakCell.imageView.image = image;
weakCell.imageView.contentMode = UIViewContentModeScaleAspectFit;
weakCell.imageView.clipsToBounds = YES;
weakCell.imageView.frame = CGRectMake(5, 5, 60, 60);
}
failure:nil];
}
答案 0 :(得分:0)
如果您想从服务器获取图像,然后将其加载到单元格上,则表格单元格无法正常升级,
您可以使用SDWebImage Library从服务器加载图片,请检查此链接SDWEbImage
如果您想添加活动指标,请查看此https://github.com/JJSaccolo/UIActivityIndicator-for-SDWebImage
#import <SDWebImage/UIImageView+WebCache.h>
in cellForRowAtIndexPath
[weakCell.myImage setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"mawgif-log.png"] options:SDWebImageRefreshCached usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];