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

  • SEARCH
  • Home
  • 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 9196335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:49:42+00:00 2026-06-17T21:49:42+00:00

I am having getting my tableview to scroll smoothly when loading in images from

  • 0

I am having getting my tableview to scroll smoothly when loading in images from NSData.

Some background … I’m storing image NSData in Core Data (using the ‘allows external storage’ option so i dont think storing the URLs or something like that is the solution here). Further, I am storing two types of data, one high res with UIImagePNGRepresentation, and one low res with UIImageJPGRepresentation. I am loading in the low res images for my table view. The image property on the entry object is not stored in core data, its set after the fact. Here is how I am doing it:

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

    DMLogTableViewCell *cell = (DMLogTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:@"LogCell" forIndexPath:indexPath];

    [cell setGradients:@[[UIColor whiteColor], [UIColor lightTextColor]]];
    Entry *entry = [self.fetchedResultsController objectAtIndexPath:indexPath];
    UIImage *entryImage = entry.image;

    if (entryImage)
        cell.rightImageView.image = entryImage;
    else {
        NSOperationQueue *oQueue = [[NSOperationQueue alloc] init];
        [oQueue addOperationWithBlock:^(void) {
            UIImage *image = [UIImage imageWithData:entry.photo.lowResImageData];
            if (!image) image = [UIImage imageNamed:@"defaultImage.png"];
            entry.image = image;
        }];
        [oQueue addOperationWithBlock:^(void) {
            [[NSOperationQueue mainQueue] addOperationWithBlock:^(void) {
                DMLogTableViewCell *cell = (DMLogTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                cell.rightImageView.image = entry.image;
            }];
        }];

    }

    return cell;
}

Any ideas on how to get this to run more smoothly? Any help is greatly appreciated!

Thanks

UPDATE

This has gotten me much closer, but there is still a little bit of jerkiness . . .
(within cellForRowAtIndexPath)

    UIImage *entryImage = entry.image;

    if (entryImage)
        cell.rightImageView.image = entryImage;
    else {
        [self.imageQueue addOperationWithBlock:^(void) {
            UIImage *image = [UIImage imageWithData:entry.photo.lowResImageData];
            if (!image) image = [UIImage imageNamed:@"bills_moduleIcon.png"];
            entry.image = image;
            [entry.image preload];

            [[NSOperationQueue mainQueue] addOperationWithBlock:^(void) {
                DMLogTableViewCell *cell = (DMLogTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                cell.rightImageView.image = entry.image;
            }];
        }];
    }

that preload method is in a cateogory on UIImageView and looks like this:

- (void)preload
{
    CGImageRef ref = self.CGImage;
    size_t width = CGImageGetWidth(ref);
    size_t height = CGImageGetHeight(ref);
    CGColorSpaceRef space = CGColorSpaceCreateDeviceRGB();
    CGContextRef context = CGBitmapContextCreate(NULL, width, height, 8, width * 4, space, kCGImageAlphaPremultipliedFirst);
    CGColorSpaceRelease(space);
    CGContextDrawImage(context, CGRectMake(0, 0, width, height), ref);
    CGContextRelease(context);
}

I think my next plan of attack is to mess around with the size of the images stored (as mentioned in the comments) or perhaps trying to not update the imageViews while the table is scrolling. Any thoughts on those two methods are much appreciated! ill check back in when i’ve done that

UPDATE 2
Many many thanks for everyone who helped me out with this! Here was the final solution (in cellForRowAtIndexPath:

    if (entryImage)
        cell.rightImageView.image = entryImage;
    else {
        [self.imageQueue addOperationWithBlock:^(void) {
            UIImage *image = [UIImage imageWithData:entry.photo.lowResImageData];
            if (!image) image = [UIImage imageNamed:@"bills_moduleIcon.png"];
            entry.image = [image scaleToSize:cell.rightImageView.frame.size];

            [[NSOperationQueue mainQueue] addOperationWithBlock:^(void) {
                DMLogTableViewCell *cell = (DMLogTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
                cell.rightImageView.image = entry.image;                
            }];
        }];
    }

adding a new category method to UIImage:

-(UIImage*)scaleToSize:(CGSize)size
{
    UIGraphicsBeginImageContext(size);
    [self drawInRect:CGRectMake(0, 0, size.width, size.height)];
    UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return scaledImage;
}

Scrolling is now perfectly smooth. Awesome

  • 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-06-17T21:49:43+00:00Added an answer on June 17, 2026 at 9:49 pm

    A couple of issues:

    1. I’d want to see how much time these two lines are taking:

      Entry *entry = [self.fetchedResultsController objectAtIndexPath:indexPath];
      UIImage *entryImage = entry.image;
      

      While I gather that entry.image is a cached image, I wouldn’t be so confident that objectAtIndexPath:indexPath isn’t actually retrieving the NSData from Core Data (which is a good portion of the performance issue in storing images in a local database rather than the file system). I’d be inclined to do this in the background queue.

    2. I don’t understand why you’re adding two operations to oQueue (which could operate concurrently!). It should just be as follows, so you don’t try to dispatch to main queue until the image is retrieved:

      [oQueue addOperationWithBlock:^(void) {
          UIImage *image = [UIImage imageWithData:entry.photo.lowResImageData];
          if (!image) image = [UIImage imageNamed:@"defaultImage.png"];
          entry.image = image;
      
          [[NSOperationQueue mainQueue] addOperationWithBlock:^(void) {
              DMLogTableViewCell *cell = (DMLogTableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];
              cell.rightImageView.image = entry.image;
          }];
      }];
      
    3. It’s probably not material, but you really shouldn’t create a new NSOperationQueue for each cell. You should define a class property that is a NSOperationQueue, initialize it in viewDidLoad, and then use that queue in cellForRowAtIndexPath. It’s not material, I’m sure, but it’s not worth the overhead of creating a queue for each row of your table. (And if you ever go to server-based image retrieval, using a single queue is very important so you can control the maxConcurrentOperationCount.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having issues getting specific background images to display in Firefox/Opera, all other browsers are
I'm having a lot of difficulty getting core data to work in my application.
im having trouble getting a string (containing a URL) from one activity to another.
I'm having trouble getting a scrollview (within a table view) to scroll. Basically, I
I am having trouble getting my UITableViewController to reload/refresh the data. I have a
Having trouble getting the oauth access token and secret exchanged from the request tokens
I've working on a program and I'm having issues getting a tableView to update.
I am having Tableview which shows comments on facebook post. I am getting comments
I'm having some trouble here. I've got a tableview, with 7 cells, all of
Having trouble getting the javascript alert to display from my code behind. c# -

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.