【发布时间】:2019-07-20 22:23:10
【问题描述】:
我正在寻找有关我的自定义 UITableview 单元格图像的解决方案。
我在我的自定义 UITableview 单元格中加载了一些信息(标签 + UIimageview),工作正常,但是由于 iOS 12,当我向下滚动时它并不平滑(它在我第一次向下滚动时会滞后,然后它在平滑时我正在向上滚动,可能与缓存图像有关)。
RecipeTableCell *cell = (RecipeTableCell *)[self.UITableView
dequeueReusableCellWithIdentifier:CellIdentifier];
// Configure the cell...
if (cell == nil)
{
cell = [[RecipeTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Display recipe in the table cell
Recipe *recipe = nil;
recipe = [recipes objectAtIndex:indexPath.row];
recupereNomFavoris = [[recipes objectAtIndex:indexPath.row] valueForKey:@"favoris"];
recupereImage = [[recipes objectAtIndex:indexPath.row] valueForKey:@"image"];
recupereNom = [[recipes objectAtIndex:indexPath.row] valueForKey:@"name"];
recupereLien = [[recipes objectAtIndex:indexPath.row] valueForKey:@"lien"];
recupereGenre = [[recipes objectAtIndex:indexPath.row] valueForKey:@"genre"];
}
}
//Display cells informations
cell.nameLabel.text = recipe.name;
cell.genre.text = recipe.genre;
cell.thumbnailImageView.image = [UIImage imageNamed:recipe.image];
我尝试添加异步解决方案,但加载图像需要 1 秒以上。
dispatch_queue_t queue =dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
UIImage *image = [UIImage imageNamed:recipe.image];// Load from file or Bundle as you want
dispatch_sync(dispatch_get_main_queue(), ^{
cell.thumbnailImageView.image = image;
});
});
所有图像大小都在 1 到 20kb 之间,我在本地加载它们。我在我的 IB 中使用约束(重量和宽度 + 布局约束)。
我尝试实现 SDWEBIMAGE 但它只允许您加载 URL 图像。
有什么建议吗?我正在努力解决这个问题
【问题讨论】:
标签: ios objective-c uitableview uiimageview