Tibbe
Tibbe

Reputation: 417

Retrieve images from parse before UITableVIew has loaded?

Everything works fine except that the images in the cell are showing up after a disturbing delay. About 0,3 seconds after the tableView has finished loading. I think it's pretty ugly to show a blank image for a short time...

How can I make the tableView to show up just after the images from parse are loaded (why not from the cache first?). Or I could maybe make the launch screen hold on for a longer time..? The TableView is the initial view in the app.

queryForTable

- (PFQuery *)queryForTable {
    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];

    // If no objects are loaded in memory, we look to the cache
    // first to fill the table and then subsequently do a query
    // against the network.
    if ([self.objects count] == 0) {
        query.cachePolicy = kPFCachePolicyCacheThenNetwork;

    }

    [query orderByAscending:@"name"];

    return query;
}

cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)objects
{
    static NSString *simpleTableIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
    }

    //loading icons
    PFFile *thumbnail = [objects objectForKey:self.imageKey];
    PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];
    thumbnailImageView.file = thumbnail;
    thumbnailImageView.image = [UIImage imageNamed:@"placeholder.jpg"];


    [thumbnailImageView loadInBackground:^(UIImage *image, NSError *error) {
        if (!error) {

        }
    }];



    //cell
    cell.textLabel.text = [objects objectForKey:self.textKey];

    return cell;
}

Thanks in advance :)

Upvotes: 0

Views: 499

Answers (2)

Kevin Pimentel
Kevin Pimentel

Reputation: 1916

I think the best way to do this would be the way facebook does it on their app. Facebook shows an empty gray container where the image belongs and once the image has been downloaded they fade it in, in animation fashion. The reason I think this is the way to go is because it doesn't seem to make sense to load an image in and then potentially load another image when ready, better to just hold an empty container and load the image in once ready.

Upvotes: 1

Akshay Bhalotia
Akshay Bhalotia

Reputation: 829

There is no harm in loading the images after a short delay. This is a standard procedure and is followed by many world class apps (ever try scrolling in Facebook or Twitter app). The work around to this would be quite messy in logical and programmatic terms.

Upvotes: 1

Related Questions