我正在使用異步(背景)圖像加載UITableviewCell
稱爲SDWebImage圖書館。但滾動tableview時仍然面臨巨大的滯後。iOS的tableview滯後滾動時加載圖像imageview
我做錯了什麼?
加載的圖像尺寸是相當大的周圍1000×1000
代碼,加載圖像的細胞:
[cell.image sd_setImageWithURL:[NSURL URLWithString:imageUrl]
placeholderImage:[UIImage imageNamed:@"image.png"]];
這裏我加載的所有信息,以實現代碼如下細胞:
-(void)viewDidLoad{
[super viewDidLoad];
NSString *identifier = @"newsItem";
UINib *nib = [UINib nibWithNibName:@"NewsTableViewCell" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:identifier];
self.dataSource = [[NewsDataSource alloc] initWithQuery:[self getQuery]
populateCell:^UITableViewCell * _Nonnull(UITableView * _Nonnull tableView,
NSIndexPath * _Nonnull indexPath,
FIRDataSnapshot * _Nonnull snap) {
NewsItem *newsItem = [[NewsItem alloc] initWithDictionary:snap.value];
NSURL *url = [NSURL URLWithString:newsItem.image];
NSString *imageUrl = url.absoluteString;
NSData *data = [NSData dataWithContentsOfURL:url];
NewsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
cell.image.layer.masksToBounds = YES;
cell.Title.text = newsItem.title;
cell.category.text = [newsItem.categories objectAtIndex:0];
cell.subTitle.text = newsItem.subTitle;
[cell.image sd_setImageWithURL:[NSURL URLWithString:imageUrl]
placeholderImage:[UIImage imageNamed:@"image.png"]];
cell.image.contentMode = UIViewContentModeScaleAspectFill;
[cell.image setFrame:CGRectMake(0,0,cell.frame.size.width,cell.frame.size.height)];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}];
[self.dataSource bindToView:self.tableView];
self.tableView.delegate = self;
}
你能顯示cellforrowatindexpath的整個代碼嗎? –
添加整個代碼爲信息加載單元格 – kosas
刪除此行'NSData * data = [NSData dataWithContentsOfURL:url];'並參見 – Krunal