UITableView Scroll Lags with Parse Images

时间:2014-08-11 21:19:15

标签: ios objective-c uitableview parse-platform

我已经看到了其他几个线程,但没有使用Parse。我们有三件事正在进行中。首先,滚动时滞后的TableView。第二,自定义单元格带有图像和标签。最后,ParsePull类获取数据。我们为此创建了一个单独的类,以将其用于其他ViewControllers。

我非常确定问题是每次屏幕上出现细胞时都会抓取每个图像,但我不知道如何修复它。以下是每个代码的相关代码。

UITableView使用以下方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!self.eventData.count) {
        ParallaxEventCell *loadCell = (ParallaxEventCell *)[tableView dequeueReusableCellWithIdentifier:@"loadingCell" forIndexPath:indexPath];
        return loadCell; 
    } else{
        ParallaxEventCell *cell = (ParallaxEventCell *)[tableView dequeueReusableCellWithIdentifier:@"eventCell" forIndexPath:indexPath];
            //load an event cell
            [cell setUpEvent:[self.eventData objectAtIndex:indexPath.row]];

            return cell;    
    }
}

ParallaxEventCell:

-(void)setUpEvent:(id)event{

    self.clipsToBounds = YES;
    self.titleLabel.text = [event objectForKey:@"eventTitle"];
    self.venueNameLabel.text = [event objectForKey:@"eventVenue"];
    self.priceLabel.text = [event objectForKey:@"eventPrice"];
    self.customDateLabel.text = [self dateStringFromDate:[event objectForKey:@"eventDate"]];
    self.eventURL = [event objectForKey:@"urlString"];
    self.geoPoint = [event objectForKey:@"GeoPoint"];
    self.descriptionText = [event objectForKey:@"eventDescription"];


    [ParsePull picturefromFile:[event objectForKey:@"eventImage"] withCompletion:^(UIImage *returnedImage) {
        self.customImageView.clipsToBounds = NO;
        self.customImageView.image = returnedImage;
        NSLog(@"setUpEvent");
    }];
}

- (void)setImage:(UIImage *)image
{
    // Store image
    self.customImageView.image = image;

    // Update padding
    [self setImageOffset:self.imageOffset];
}

ParsePull

+(void)picturefromFile:(PFFile *)file withCompletion:(PictureBlock)logo{
    NSLog(@"pictureFromFile");
    [file getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
        if (!error) {
             logo([UIImage imageWithData:data]);
                    }
        else{
        logo(nil);
        }
    }];
}

0 个答案:

没有答案