Ios 自定义UITableViewCells的UITableView滚动性能

Ios 自定义UITableViewCells的UITableView滚动性能,ios,uitableview,Ios,Uitableview,要求:在单个自定义TableViewCell中显示多达9个数据点,其中有2个UILabels、4个UIButtons和3个UIImages 问题陈述:如果将这些ui图像和ui按钮添加为子视图,则使用自定义UITableViewCell滚动会不顺畅。如果问题在于一个单元格上的视图数量,则UITableView中大约有500行。 尝试将单元格图层的shouldRasterize属性设置为YES yourCell.layer.shouldRasterize = YES; yourCell.layer.

要求:在单个自定义TableViewCell中显示多达9个数据点,其中有2个
UILabels
、4个
UIButtons
和3个
UIImages


问题陈述:如果将这些
ui图像
ui按钮
添加为子视图,则使用自定义
UITableViewCell
滚动会不顺畅。如果问题在于一个单元格上的视图数量,则
UITableView中大约有500行。
尝试将单元格图层的shouldRasterize属性设置为YES

yourCell.layer.shouldRasterize = YES;
yourCell.layer.rasterizationScale = [UIScreen mainScreen].scale;

但请记住,所有动画视图(如UIActivityIndicatorView)都会强制单元格在每一帧上重新绘制其内容。

我使用的这个库非常完美

您只需将
#导入到您的项目中,您还可以在下载图像时定义占位符,只需使用以下代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *MyIdentifier = @"MyIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];

    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                       reuseIdentifier:MyIdentifier] autorelease];
    }

    // Here we use the new provided setImageWithURL: method to load the web image
    [cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
                   placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

    cell.textLabel.text = @"My Text";
    return cell;
}
它还缓存下载的图像,并为您提供出色的性能


希望它能帮助你

是否要显示从服务器获取的图像?根据来自服务器的数据动态添加所有图像。所有图像都存储在本地。问题在于图像,但是您应该提供从何处获取图像的更多信息您可以先尝试下载所需的图像,然后重新加载tableView,或者您可以使用SDWebImage下载图像。