Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7639361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:23:56+00:00 2026-05-31T08:23:56+00:00

This is the code I have. It works fine for the first 3 entries,

  • 0

This is the code I have. It works fine for the first 3 entries, then on the 4th entry, it starts showing the same cell content as other cells, despite the height of each cell being correct. Can anybody spot any problems that i’m not seeing here? The cell.textLabel.text is there purely for testing purposes, and comes back as the correct cell number, even if the contents of the cell aren’t right. Since it’s set at the same time as the content, this leads me to believe the problem is not in cellForRowAtIndexPath.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";

    JCell *cell = (JCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    UIImageView *imageView;
    if (cell == nil) {
        cell = [[JCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

        imageView = [[UIImageView alloc] init];
        imageView.contentMode = UIViewContentModeCenter;

        [cell addSubview:imageView];

    }

    UIImage *image = [self.mediaDelegate largeThumbnailForMediaAtIndex:indexPath.row];
    imageView.frame = CGRectMake(0, IMAGE_SPACING, image.size.width, image.size.height);
    imageView.image = image;
    imageView.center = CGPointMake(cell.bounds.size.width / 2, imageView.center.y);

    cell.textLabel.text = [NSString stringWithFormat:@"%i", indexPath.row];

    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    int mediaHeight = [self.mediaDelegate heightForLargeThumbnailForMediaAtIndex:indexPath.row];    

    return mediaHeight + (IMAGE_SPACING * 2);
}

It’s always going to be a JImage, because i haven’t started on movie support yet.

-(UIImage *)largeThumbnailForMediaAtIndex:(int)index
{
    id media = [self.media objectAtIndex:index];
    if ([media isKindOfClass:[JImage class]]) {
        JImage *image = media;
        return [image getLargeThumbnail];
    }
    else if ([media isKindOfClass:[JMovie class]]) {
        JMovie *movie = media;
        return [movie getLargeThumbnail];
    }
    else {
        return nil;
    }
}

-(UIImage *)getLargeThumbnail {
    if (self.largeThumbnail == nil) {
        UIImage *originalImage = [UIImage imageWithContentsOfFile:self.originalImage];
        UIImage *resizedImage = [originalImage imageScaledToFitSize:LARGE_THUMBNAIL_SIZE];
        self.largeThumbnail = @"Generating";
        dispatch_queue_t myQueue = dispatch_queue_create("LargeThumbnailQueue", 0);
        dispatch_async(myQueue, ^{
            NSString *filePath = [JImage writeImageToFile:resizedImage];
            self.largeThumbnail = filePath;
        });

        return resizedImage;

    }
    else if ([_largeThumbnail isEqualToString:@"Generating"]) {
        UIImage *originalImage = [UIImage imageWithContentsOfFile:self.originalImage];
        UIImage *resizedImage = [originalImage imageScaledToFitSize:LARGE_THUMBNAIL_SIZE];
        return resizedImage;
    }
    else {
        NSString *filePath = self.largeThumbnail;
        UIImage *image = [UIImage imageWithContentsOfFile:filePath];
        return image;
    }

}


+(NSString *)writeImageToFile:(UIImage *)image {

    NSData *fullImageData = UIImageJPEGRepresentation(image, 1.0);

    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Images/"];

    NSFileManager *fileManager = [NSFileManager defaultManager];
    BOOL isDirectory = NO;
    BOOL directoryExists = [fileManager fileExistsAtPath:path isDirectory:&isDirectory];
    if (directoryExists) {
    } else {
        [fileManager createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:nil];
    }

    NSString *retinaSupport;
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] && [[UIScreen mainScreen] scale] == 2){
        retinaSupport = @"@2x";
    }

    NSString *name = [NSString stringWithFormat:@"%@%@.jpg", [JMedia generateUuidString], retinaSupport];
    NSString *filePath = [path stringByAppendingPathComponent:name];
    [fullImageData writeToFile:filePath atomically:YES];

    return filePath;
}

Any assistance or help with this problem is greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:23:58+00:00Added an answer on May 31, 2026 at 8:23 am

    when you reuse a cell (ie. you don’t enter if (cell == nil) you don’t have an imageView. imageView will be nil.

    Add a tag to retrieve that imageView when you reuse your cells:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"Cell";
        JCell *cell = (JCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        UIImageView *imageView;
        if (cell == nil) {
            cell = [[JCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
            imageView = [[UIImageView alloc] init];
            imageView.contentMode = UIViewContentModeCenter;
            imageView.tag = 1234;
            [cell addSubview:imageView];
    
        }
        imageView = [cell viewWithTag:1234];
    
        UIImage *image = [self.mediaDelegate largeThumbnailForMediaAtIndex:indexPath.row];
        imageView.frame = CGRectMake(0, IMAGE_SPACING, image.size.width, image.size.height);
        imageView.image = image;
        imageView.center = CGPointMake(cell.bounds.size.width / 2, imageView.center.y);
    
        cell.textLabel.text = [NSString stringWithFormat:@"%i", indexPath.row];
        return cell;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have this JQuery code: $('#dialog-message').attr(title, t); It works fine the first time it's
I have this code, which works fine, but I would like to be able
I have this piece of code that works fine in subsonic 2.2, I migrated
I have a Firefox 3.6.2 problem (3.5.x works just fine). This is the code:
I have this code, which works fine: if ( $('table#attribute_Size input.quantitycheckbox:checked').length == 0 )
I have this code as a cffunction that works fine: <cfcomponent extends=core.core> <cffunction name=loadService
I have this code that works in a unit test but doesn't work when
I have this code which compiles and works as expected: class Right {}; class
I have this code in my cfm, which works <cfif not StructIsEmpty(form)> <cfset larray
I have this code to write to a file, it works perfect but I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.