UITableView,滚动时抽搐

时间:2015-04-08 05:23:32

标签: ios

/ 问题是,我在UITableview中创建了自己的内容视图并进行了展示。滚动表格视图时给出了Jerking。如何解决此问题。 /

[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];

/ ImageDetails,我从服务器接收并使用延迟加载加载。 /

UIImageView *lblImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 60, 60)];
lblImage.contentMode = UIViewContentModeScaleAspectFill;
[cell.contentView addSubview:lblImage];

if([[[lArray objectAtIndex:indexPath.row] objectForKey:@"Foto"] length] > 0){
    NSURL *imageURL = [NSURL URLWithString:[[lMovikidListArray objectAtIndex:indexPath.row] objectForKey:@"MovikitFoto"]];
    NSString *key = [[[lArray objectAtIndex:indexPath.row] objectForKey:@"Foto"] MD5Hash];
    NSData *data = [FTWCache objectForKey:key];
    if (data) {
        UIImage *image = [UIImage imageWithData:data];
        lblImage.image = image;
    } else {
        lblImage.image = [UIImage imageNamed:@"defaultprofile.png"];
        dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
        dispatch_async(queue, ^{
            NSData *data = [NSData dataWithContentsOfURL:imageURL];
            [FTWCache setObject:data forKey:key];
            UIImage *image = [UIImage imageWithData:data];
            dispatch_sync(dispatch_get_main_queue(), ^{
                lblImage.image = image;
            });
        });
    }
    CALayer *imageLayer = lblImage.layer;
    [imageLayer setCornerRadius:lblImage.frame.size.width/2];
    [imageLayer setMasksToBounds:YES];
}
else{
    lblImage.image = [UIImage imageNamed:@"defaultprofile.png"];
}


UILabel *lblTitle = [[UILabel alloc]initWithFrame:CGRectMake(75, 10, 220, 25)];
lblTitle.text = [NSString stringWithFormat:@"%@ - %@", [[lArray objectAtIndex:indexPath.row] objectForKey:@"Name"], [[lArray objectAtIndex:indexPath.row] objectForKey:@"SimNo"]];
lblTitle.font = [UIFont boldSystemFontOfSize:14.0f];
[cell.contentView addSubview:lblTitle];

UILabel *lblSubTitle = [[UILabel alloc]initWithFrame:CGRectMake(100, 40, 195, 35)];
if([[[lArray objectAtIndex:indexPath.row] objectForKey:@"Location"] length] <= 1){
    lblSubTitle.text = LOCATION_NOT_AVAILABLE;
    lImageName = @"caution_icon.png";
}
else{
    lblSubTitle.text = [self calculateDistance:<some data>];
}
lblSubTitle.textColor = [UIColor darkGrayColor];
lblSubTitle.numberOfLines = 2;
lblSubTitle.font = [UIFont italicSystemFontOfSize:12.0f];
[cell.contentView addSubview:lblSubTitle];

/ 此图像是一个小图像,用于显示一些指示符。 /

UIImageView *lblIndicatorImage = [[UIImageView alloc]initWithFrame:CGRectMake(75, 45, 20, 20)];
lblIndicatorImage.image = [UIImage imageNamed:lImageName];
[cell.contentView addSubview:lblIndicatorImage];

[cell setNeedsDisplay];

1 个答案:

答案 0 :(得分:0)

您无法在后台线程上执行任何UIKit操作。所以只需从后台线程中删除你的图形操作就可以了。

    else {
            lblImage.image = [UIImage imageNamed:@"defaultprofile.png"];

            dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
            dispatch_async(queue, ^{

                NSData *data = [NSData dataWithContentsOfURL:imageURL];
                [FTWCache setObject:data forKey:key];

                dispatch_async(dispatch_get_main_queue(), ^{
                    UIImage *image = [UIImage imageWithData:data];
                    lblImage.image = image;

                });
            });