Search code examples
iphoneimageuitableviewcell

iOS TableView Cells


I have found many answers to problems I've encountered on here and would like to ask a question for the first time (I'm a newbie to asking for help!)

I've implemented the SDWebImage framework into an project that uses JSON parsed data to populate a UITableViewController. The images are being cached successfully but when the App first launches, all the cell images are absent. Only when I scroll up or down and the rows appear (or when I tap them to select a row) do they appear. If I go back into it, all the images are there cached and work fine. It's just the first launch that I am missing all my images. I've pasted what I have here in the hope someone can post a simple solution. Got a feeling it's something minor that I have to do to make them appear on first launch.

Code follows:

static NSString *MyIdentifier = @"Maincell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];


if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier];
}

UIFont *wireBold = [UIFont fontWithName:@"Helvetica" size:14.0f];
cell.textLabel.text = [[news objectAtIndex:indexPath.row]objectForKey:@"Title"];
cell.textLabel.font = wireBold;
cell.textLabel.textColor = [UIColor blackColor];

UIFont *wireSub = [UIFont fontWithName:@"Sintony" size:10.0f];

cell.detailTextLabel.text = [[news objectAtIndex:indexPath.row]objectForKey:@"Name"];

cell.detailTextLabel.font = wireSub;
cell.detailTextLabel.textColor = [UIColor grayColor];

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

NSString *filePath = [[news objectAtIndex:indexPath.row]objectForKey:@"Image"];

NSString *urlString = [NSString stringWithFormat:@"http://www.mywebhost/images/%@.png",filePath];

[cell.imageView setImageWithURL:[NSURL URLWithString:urlString] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

return cell;

Solution

  • Are you at least seeing placeholder.png initially? Is that image appropriately sized for your cell? Reading through comments in other posts, it appears that if you do not have a placeHolder image then it won't show the loaded image until the tableView is reloaded. That is consistent with the behavior you reported.