Skip to content

Instantly share code, notes, and snippets.

@okiess
Created November 5, 2012 11:52
Show Gist options
  • Save okiess/4016846 to your computer and use it in GitHub Desktop.
Save okiess/4016846 to your computer and use it in GitHub Desktop.
Thumbnail bugfix
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NewsItem *item = [self.newsItems objectAtIndex:indexPath.row];
if (indexPath.row == 0 && item.imageUrl != nil && _showTeaser) {
// Teaser Cell
static NSString *CellIdentifier = @"NewsListCell1";
NewsListTeaserCell *cell = (NewsListTeaserCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[NewsListTeaserCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
/// ADD THIS!!! ///
cell.thumbnailImageView.image = nil;
cell.titleLabel.text = item.title;
cell.subTitleLabel.text = [NSString stringWithFormat:@"%@ | %@", item.date, self.selectedCategory];
if (item.imageUrl != nil && [item.imageUrl length] > 0) {
[cell.thumbnailImageView setImageWithURL:[NSURL URLWithString:item.imageUrl] placeholderImage:nil];
} else {
cell.thumbnailImageView.image = [UIImage imageNamed:@"placeholder"];
}
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(showDetails:)];
recognizer.direction = UISwipeGestureRecognizerDirectionLeft;
cell.tag = indexPath.row;
[cell addGestureRecognizer:recognizer];
return cell;
} else {
// Regular Thumbnail Cell
static NSString *CellIdentifier = @"NewsListCell2";
NewsListWithThumbnailTableViewCell *cell = (NewsListWithThumbnailTableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[NewsListWithThumbnailTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
/// ADD THIS!!! ///
cell.thumbnailImageView.image = nil;
cell.titleLabel.text = item.title;
cell.subTitleLabel.text = [NSString stringWithFormat:@"%@ | %@", item.date, self.selectedCategory];
if (item.imageUrl != nil && [item.imageUrl length] > 0) {
[cell.thumbnailImageView setImageWithURL:[NSURL URLWithString:item.imageUrl]
placeholderImage:[UIImage imageNamed:@"placeholder"]];
} else {
cell.thumbnailImageView.image = [UIImage imageNamed:@"placeholder"];
}
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(showDetails:)];
recognizer.direction = UISwipeGestureRecognizerDirectionLeft;
cell.tag = indexPath.row;
[cell addGestureRecognizer:recognizer];
return cell;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment