3

我有滚动表格的非常严重的问题。

最初我使用 GCD 在背景中加载图像并在表格单元格上进行设置。但表格滚动不顺畅。所以我为此使用了 SDWebImage,但同样的事情正在发生。

谁能告诉我这个原因。为什么表格滚动不像预期的那样平滑。

请让我知道您的意见,因为我的应用程序正在等待它的发布,只是为了相同的目的。

代码 :

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

           NSString *CellIdentifier = @"Cell";
        customCellForExhibitor *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

        if (cell == nil)
        {
            NSArray *xibPath = [[NSBundle mainBundle]loadNibNamed:@"customCellForExhibitor" owner:self options:nil];
            for (id fileObject in xibPath)
            {
                cell = (customCellForExhibitor*)fileObject;
            }
        }

        objDataModel = [parserDataContentArray objectAtIndex:indexPath.section];

        cell.exhibitorNameLabel.text = [objDataModel exhibitorNameObjectClass];
        cell.exhibitorText.text = [objDataModel exhibitorOfferObjectClass];
        cell.exhibitorSponsorType.text = [objDataModel exhibitorSponsorTypeObjectClass];

        [cell.exhibitorSponsorType setTextAlignment:NSTextAlignmentRight];



//        #pragma mark GCD;
//    
//        NSString *ImageURL = [[parserDataContentArray objectAtIndex:indexPath.section] exhibitorImageObjectClass];
////        NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
////        cell.exhibitorImage.image = [UIImage imageWithData:imageData];
//
//        dispatch_queue_t concurrentQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
//        //this will start the image loading in bg
//        dispatch_async(concurrentQueue, ^{
//        NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
//        
//        //this will set the image when loading is finished
//        dispatch_async(dispatch_get_main_queue(), ^{
//            
//            cell.exhibitorImage.image = [UIImage imageWithData:imageData];
//            [cell setNeedsDisplay];
//
//                                                    });
//                                        });

     NSString *ImageURL = [[parserDataContentArray objectAtIndex:indexPath.section] exhibitorImageObjectClass];
     [cell.exhibitorImage setImageWithURL:[NSURL URLWithString:ImageURL]
                      placeholderImage:[UIImage imageNamed:@"placeholder.png"]];



        if ([cell.exhibitorSponsorType.text isEqualToString:@"Gold"]) {
            cell.exhibitorSponsorType.textColor = [UIColor colorWithRed:255/255.0 green:215/255.0 blue:0 alpha:1];

        }

        else if ([cell.exhibitorSponsorType.text isEqualToString:@"Silver"]){
            cell.exhibitorSponsorType.textColor = [UIColor colorWithRed:192/255.0 green:192/255.0 blue:192/255.0 alpha:1];
        }
        else cell.exhibitorSponsorType.textColor = [UIColor colorWithRed:229/255.0 green:228/255.0 blue:226/255.0 alpha:1];

        return cell;



}

谢谢您最好的问候。

4

1 回答 1

0

使用延迟加载文件,这里是你可以在这里找到的参考,以及它是如何实现的演示。

https://stackoverflow.com/a/18032907/1305001

[cell addSubview:[self addViewWithURL:ImageURL NFrame:CGRectMake(0, 0, 50, 50)]];

在 cellForRow 下方添加此方法

-(UIView*)addViewWithURL:(NSString*)urlStr NFrame:(CGRect)rect
{
    LazyLoad *lazyLoading;

    lazyLoading = [[LazyLoad alloc] init];
    [lazyLoading setBackgroundColor:[UIColor grayColor]];
    [lazyLoading setFrame:rect];

    [lazyLoading loadImageFromURL:[NSURL URLWithString:urlStr]];
    return lazyLoading;
}

将 LazyLoad.m 文件的 init 方法中的占位符设置为

-(id)init{
    if (self==[super init]) {
        [self setImage:[UIImage imageNamed:@"placeholder.png"]];
    }
    return self;
}

并将 LazyLoad.h 文件的超类从 UIView 更改为 UIImageView 作为

@interface LazyLoad : UIImageView
于 2013-08-08T06:34:37.557 回答