Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- // this is where the data for each cell is
- NSDictionary *dataForThisCell = cachedData.posts[indexPath.row][@"data"];
- // 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.
- post *cell = (post *) [self.tableView dequeueReusableCellWithIdentifier:@"postWithImage"];
- if (cell == nil) {
- cell = [[[NSBundle mainBundle]loadNibNamed:@"postWithImage" owner:self options:nil]objectAtIndex:0];
- [cell styleCell];
- }
- // if this cell has an image we need to stick it in the cell
- NSString *lowerCaseURL = [dataForThisCell[@"url"] lowercaseString];
- if([lowerCaseURL hasSuffix: @"gif"] || [lowerCaseURL hasSuffix: @"bmp"] || [lowerCaseURL hasSuffix: @"jpg"] || [lowerCaseURL hasSuffix: @"png"] || [lowerCaseURL hasSuffix: @"jpeg"]) {
- // if this cell doesnt have an UIImageView, add one to it. Cells are recycled so this only runs several times
- if(cell.preview == nil) {
- cell.preview = [[UIImageView alloc] init];
- [cell.contentView addSubview: cell.preview];
- cell.preview.frame = CGRectMake( 0, 0, 100, 100);
- }
- // download image
- [cell.preview cancelImageRequestOperation];
- [cell.preview setImageWithURL:[NSURL URLWithString:dataForThisCell[@"url"]] placeholderImage:[UIImage imageNamed:@"thumbnailLoading.png"]];
- }
- // set title of the cell
- cell.title.text = [NSString stringWithFormat: @"%@\n\n\n\n\n", dataForThisCell[@"title"]];
- [cell setNeedsLayout];
- // returns my customized cell
- return cell;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement