Advertisement
Guest User

Untitled

a guest
May 22nd, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2.    
  3.     // this is where the data for each cell is
  4.     NSDictionary *dataForThisCell = cachedData.posts[indexPath.row][@"data"];
  5.    
  6.     // this creates a new cell or grabs a recycled one, I put NSLogs in the if statement to make sure they are being recycled, they are.
  7.     post *cell = (post *) [self.tableView dequeueReusableCellWithIdentifier:@"postWithImage"];
  8.     if (cell == nil) {
  9.         cell = [[[NSBundle mainBundle]loadNibNamed:@"postWithImage" owner:self options:nil]objectAtIndex:0];
  10.         [cell styleCell];
  11.     }
  12.    
  13.     // if this cell has an image we need to stick it in the cell
  14.     NSString *lowerCaseURL = [dataForThisCell[@"url"] lowercaseString];
  15.     if([lowerCaseURL hasSuffix: @"gif"] || [lowerCaseURL hasSuffix: @"bmp"] || [lowerCaseURL hasSuffix: @"jpg"] || [lowerCaseURL hasSuffix: @"png"] || [lowerCaseURL hasSuffix: @"jpeg"]) {
  16.        
  17.         // if this cell doesnt have an UIImageView, add one to it. Cells are recycled so this only runs several times
  18.         if(cell.preview == nil) {
  19.             cell.preview = [[UIImageView alloc] init];
  20.             [cell.contentView addSubview: cell.preview];
  21.             cell.preview.frame = CGRectMake( 0, 0, 100, 100);
  22.         }
  23.        
  24.         // download image
  25.         [cell.preview cancelImageRequestOperation];
  26.         [cell.preview setImageWithURL:[NSURL URLWithString:dataForThisCell[@"url"]] placeholderImage:[UIImage imageNamed:@"thumbnailLoading.png"]];
  27.        
  28.        
  29.     }
  30.    
  31.     // set title of the cell
  32.     cell.title.text = [NSString stringWithFormat: @"%@\n\n\n\n\n", dataForThisCell[@"title"]];
  33.  
  34.     [cell setNeedsLayout];
  35.    
  36.     // returns my customized cell
  37.     return cell;
  38.    
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement