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 6143873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:34:39+00:00 2026-05-23T18:34:39+00:00

I have a uitableview which stores one image in one cell. Its image get

  • 0

I have a uitableview which stores one image in one cell. Its image get loaded from internet. The problem is the application get slow till its image get loaded from internet. So I want to put a mechanism that it first get loaded with a default image and when it gets the original then the default image will be replaced by the original one.

Give me any tutorial or any sample code for it.

Thanks in advance.

  • 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-23T18:34:40+00:00Added an answer on May 23, 2026 at 6:34 pm

    Get your image trough some other thread …. and use notification or delegate to keep track of any change in image download … suppose you are using notification …. then in class which you set as observer for that notification reload the data of tableView …. so your table image will get updated where there was so default image …. for more detail lets take an example ….. Make a operation class to downloading the image we call it thumb …. In this example I make 2 classes
    1. PhotoGalleryVC which shows a list of thumbs and some detail of each thumb and
    2. LoadGalleryThumbOp [Op = operation] downloads thumbs and post notification when done

    @protocol LoadGalleryThumbDelegate;
    @interface LoadGalleryThumbOp : NSObject{
    
        NSIndexPath* indexPathInTableView;
        id <LoadGalleryThumbDelegate> delegate;
        NSMutableData *activeDownload;
            NSURLConnection *imageConnection;
        NSString * documentPath;
        BOOL imageDownload;
    }
    @property (nonatomic, assign) NSIndexPath* indexPathInTableView;
    @property (nonatomic, retain) NSMutableData *activeDownload;
    @property (nonatomic, retain) NSURLConnection *imageConnection;
    @property (nonatomic, assign) id <LoadGalleryThumbDelegate> delegate;
    @property (nonatomic, retain) NSString * documentPath;
    @property (nonatomic) BOOL imageDownload;
    - (void)startDownload;
    - (void)cancelDownload;
    - (void) persistData:(NSData*) data;
    @end
    
    @protocol LoadGalleryThumbDelegate 
    
    - (void)appImageDidLoad:(NSIndexPath *)indexPath;
    
    @end
    

    in LoadGalleryThumbOp.m do it as

    @implementation LoadGalleryThumbOp
    
    @synthesize year;
    @synthesize indexPathInTableView;
    @synthesize delegate;
    @synthesize activeDownload;
    @synthesize imageConnection,documentPath,imageDownload;
    
    #pragma mark
    
    - (void)startDownload
    {
        self.imageDownload = YES;
        self.activeDownload = [NSMutableData data];
        NSFileManager* fm = [NSFileManager defaultManager];
        NSString* galleryDocumentPath = [self.documentPath stringByAppendingPathComponent:[NSString stringWithFormat:@"images/thumb.jpg"]];
        if ([fm fileExistsAtPath:galleryDocumentPath]) 
        {
            UIImage *image = [[UIImage alloc] initWithContentsOfFile:galleryDocumentPath ];
             self.gallery.thumpImage = image;
            self.activeDownload = nil;
            [image release];
            self.imageConnection = nil;
             [delegate appImageDidLoad:self.indexPathInTableView];
        }
        else {
            NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:
                                     [NSURLRequest requestWithURL:
                                  [NSURL URLWithString:#error yourImageUrl]] delegate:self];
            self.imageConnection = conn;
            [conn release];
        }
    }
    
    - (void)cancelDownload
    {
        [self.imageConnection cancel];
        self.imageConnection = nil;
        self.activeDownload = nil;
    }
    
    
    #pragma mark -
    #pragma mark Download support (NSURLConnectionDelegate)
    
    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
        [self.activeDownload appendData:data];
    }
    
    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
    {
        self.activeDownload = nil;
        self.imageConnection = nil;
        self.imageDownload = NO;
         [NSString stringWithFormat:@"images/thumb.jpg"]];
        [delegate appImageDidLoad:self.indexPathInTableView];
    }
    
    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
        [self persistData:self.activeDownload];    
        self.activeDownload = nil;
        self.imageConnection = nil;
        [delegate appImageDidLoad:self.indexPathInTableView];
    }
    - (void) persistData:(NSData*) data
    {
        NSFileManager* fm = [NSFileManager defaultManager];
        NSString* galleryDocumentPath = [self.documentPath stringByAppendingPathComponent:[NSString stringWithFormat:@"images/thumb.jpg"]];
        if ([[NSFileManager defaultManager] fileExistsAtPath:galleryDocumentPath]) 
        {
            NSError* err = nil;
            [fm removeItemAtPath:galleryDocumentPath error:&err];
            if (err)
                NSLog(@"%s:%@",__FUNCTION__,err);
        }
        [fm createFileAtPath:galleryDocumentPath contents:data attributes:nil];
    }
    

    this class will download the image you wanted and will call its delegate when the image is download ..
    Now comes its use part in PhotoGalleryVC use it like this

    @interface PhotoGalleryVC : UIViewController <LoadGalleryThumbDelegate>{
    
        IBOutlet UITableView* albumListTableView;
        NSMutableDictionary *imageDownloadsInProgress;
        NSArray* allThumbs;
    }
    @property (nonatomic, retain) NSMutableDictionary *imageDownloadsInProgress;
    
    - (void)appImageDidLoad:(NSIndexPath *)indexPath;
    @end
    

    in .m part

    - (void)viewDidLoad {
         self.imageDownloadsInProgress = [NSMutableDictionary dictionary];
         .....
    
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSFileManager* fm = [NSFileManager defaultManager];
        NSString* galleryDocumentPath =  [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"Gallery/%@/images/thumb.jpg",[someObj.title stringByReplacingOccurrencesOfString:@" " withString:@"_" ]]];
    //this above line is just make a seperate folder for each object and store thumbs of that object in that folder ... so make it unique some how
        if (![fm fileExistsAtPath:galleryDocumentPath]) 
        {
            LoadGalleryThumbOp *galleryThumbDownloader = [imageDownloadsInProgress objectForKey:indexPath];
            if (galleryThumbDownloader != nil && galleryThumbDownloader.imageDownload == NO)
            {
                [cell.activityIndicator stopAnimating];
                cell.albumCoverImageView.image = [UIImage imageNamed:@"no_thumb.png"];
            }
            else {
                [cell.activityIndicator startAnimating];                
            }
            [self startIconDownload:temp forIndexPath:indexPath andYear:[NSString stringWithFormat:@"%d",selectedYear]];
        }
        else
        {
            [cell.activityIndicator stopAnimating];
            cell.albumCoverImageView.image = [UIImage imageWithContentsOfFile:galleryDocumentPath];
        }
        return cell ;
    }
    
    //The following method see if there is already so downloader that is downloading same image then it simply do nothing else it create a downloader and start it     
    - (void)startIconDownload:(Gallery *)gallery forIndexPath:(NSIndexPath *)indexPath  andYear:(NSString*)yr
    {
        LoadGalleryThumbOp *galleryThumbDownloader = [imageDownloadsInProgress objectForKey:indexPath];
        if (galleryThumbDownloader == nil) 
        {
            NSString* documentsPath =    [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
            NSString* nameWithoutSpace = [gallery.title stringByReplacingOccurrencesOfString:@" " withString:@"_" ];
            NSString* galleryDocumentPath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"Gallery//%@",nameWithoutSpace]];
    
            galleryThumbDownloader = [[LoadGalleryThumbOp alloc] init];
            galleryThumbDownloader.documentPath = galleryDocumentPath;
            galleryThumbDownloader.indexPathInTableView = indexPath;
            galleryThumbDownloader.delegate = self;
            [imageDownloadsInProgress setObject:galleryThumbDownloader forKey:indexPath];
            [galleryThumbDownloader startDownload];
            [galleryThumbDownloader release];   
        }
        else if(galleryThumbDownloader.imageDownload == NO)
        {
            if (albumListTableView.dragging || albumListTableView.decelerating) {
                [galleryThumbDownloader startDownload];
            }
        }
    }
    

    finally the method which is called when a particular image is downloaded

    - (void)appImageDidLoad:(NSIndexPath *)indexPath
    {
        CustomCellPhotoGalary* cell = (CustomCellPhotoGalary*)[albumListTableView cellForRowAtIndexPath:indexPath];
        LoadGalleryThumbOp *galleryThumbDownloader = [imageDownloadsInProgress objectForKey:indexPath];
    
        if (galleryThumbDownloader != nil)
        {
            if (galleryThumbDownloader.imageDownload) 
            {
                [cell.activityIndicator stopAnimating];
                NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];                                
                        NSString* nameWithoutSpace = [temp.title stringByReplacingOccurrencesOfString:@" " withString:@"_" ];
                NSString* galleryDocumentPath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"Gallery/%@",nameWithoutSpace]];
                cell.albumCoverImageView.image = [UIImage imageWithContentsOfFile:galleryDocumentPath];
                //galleryThumbDownloader = nil;
            }
            else {
                [cell.activityIndicator stopAnimating];
                cell.albumCoverImageView.image = [UIImage imageNamed:@"no_thumb.png"];
                [self startIconDownload:temp forIndexPath:indexPath andYear:[NSString stringWithFormat:@"%d",selectedYear]];
        }
            [albumListTableView reloadData];
        }
    }
    

    woooh…..! thats a lot of code for one example
    Note : I cut out so many line so this code may not work for u directly {there may be so many errors .. }, But i hope you get the main idea behind the scene … 🙂

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

Sidebar

Related Questions

I have a uitableview 'A' which has cells, on clicking one of the cell,
I have an edit screen which is comprised of one huge UITableView. Each cell
I have a UITableView which generates its data from a pList. I have a
I have a UITableView which shows some information. The informations are from a XMLFile.
I have a custom UITableView cell which has a button and a label. I
I have a typical UITableView which displays a thumbnail image and some text. During
another weird problem with the iPhone SDK here. I have a UITableView which contains
I have a UITableView which is populated by an array, I have a button
I have a UITableView which displays about 5 cells at a time, yet in
I have a grouped UITableView which displays a number of cells, which includes both

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.