Reputation: 417
When the iOS app runs nothing shows up in the cells, the image is of type "file" in parse. I don't use the storyboard for this so I cant change the class for the imageView to PFImageView. What's missing?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *simpleTableIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
// Configure the cell
PFFile *thumbnail = [object objectForKey:@"logo"];
PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];
thumbnailImageView.image = [UIImage imageNamed:@"placeholder.png"];
thumbnailImageView.file = thumbnail;
[thumbnailImageView loadInBackground];
cell.textLabel.text = [object objectForKey:@"name"];
cell.detailTextLabel.textColor=[UIColor lightGrayColor];
cell.backgroundColor = [UIColor clearColor];
thumbnailImageView=[[PFImageView alloc] initWithFrame:CGRectMake(9, 9, 30, 30)];
[thumbnailImageView setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:thumbnailImageView];
return cell;
}
Thanks in advance!
Upvotes: 0
Views: 621
Reputation: 1916
I think the reason you can't see the image is because you are loading it in the background and setting it before the data has been obtained from parse. Could you try something like this:
// Set placeholder to show before image finishes loading
PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];
thumbnailImageView.image = [UIImage imageNamed:@"placeholder.png"];
PFFile *thumbnail = [object objectForKey:@"logo"];
[thumbnailImageView setFile:thumbnail];
[thumbnailImageView loadInBackground:^(UIImage *image, NSError *error) {
if (!error) {
// Configure your image view in here
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(9, 9, 30, 30)];
[imageView setBackgroundColor:[UIColor clearColor]];
[imageView setImage:image];
[cell.contentView addSubview:imageView];
}
}];
Try something along these lines.
Upvotes: 0
Reputation: 8501
Do you actually need these 3 lines...
thumbnailImageView=[[PFImageView alloc] initWithFrame:CGRectMake(9, 9, 30, 30)];
[thumbnailImageView setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:thumbnailImageView];
You are already casting your existing ImageView to a PFImageView...
PFImageView *thumbnailImageView = (PFImageView*)[cell viewWithTag:100];
Which in turn should be the image view in you table cell. Does loadInBakground
work well with table cells though? You could hit issues where the row its getting the image for may have already been reused by another image
Upvotes: 1