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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:32:34+00:00 2026-06-04T05:32:34+00:00

I am downloading images in table asynchronously. when table appears first time then connecion:didrecieveData

  • 0

I am downloading images in table asynchronously. when table appears first time then connecion:didrecieveData is not called but when I move the up or down then it is called and images are displayed. kindly help

table View class:

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

    static NSString *CellIdentifier = @"Cell";

    customiseForVideos *cell =(customiseForVideos *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"customiseForVideos" owner:self options:nil];
        cell=tblCell;
    }
    else{
        AsyncImageView* oldImage = (AsyncImageView*)
        [cell.contentView viewWithTag:999];
        [oldImage removeFromSuperview];

    }
    [cell.imageActivity startAnimating];

    CGRect frame;
    frame.size.width=65; frame.size.height=70;
    frame.origin.x=24; frame.origin.y=12;
    AsyncImageView* asyncImage = [[[AsyncImageView alloc]
                                   initWithFrame:frame] autorelease];
    asyncImage.tag = 999;
    NSURL* url = [NSURL URLWithString:[[videoCollection objectAtIndex:indexPath.row] videoImageUrl]];
        //NSLog(@"%@",url);
    [asyncImage loadImageFromURL:url activity:cell.imageActivity];

    [cell.contentView addSubview:asyncImage];

    if((indexPath.row%2)==0)
        cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"green-cell-row.png"]] autorelease];
    else{
        cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"blue-cell-row.png"]] autorelease];
    }
    return cell;
}

AsyncImageView class:

- (void)loadImageFromURL:(NSURL*)url activity:(UIActivityIndicatorView *)cellActivity {
    activityOnCell=cellActivity;
    activityOnCell.hidden=NO;
    if (self.connection!=nil) { [self.connection release]; } //in case we are downloading a 2nd image
    if (data!=nil) { [data release]; }

    NSURLRequest* request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    self.connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; //notice how delegate set to self object
    NSLog(@"%@",request);
        //TODO error handling, what if connection is nil?
}


//the URL connection calls this repeatedly as data arrives
- (void)connection:(NSURLConnection *)theConnection didReceiveData:(NSData *)incrementalData {
    if (data==nil) { data = [[NSMutableData alloc] initWithCapacity:2048]; } 
    [data appendData:incrementalData];
}

//the URL connection calls this once all the data has downloaded
- (void)connectionDidFinishLoading:(NSURLConnection*)theConnection {
    //so self data now has the complete image 
    [self.connection release];
    self.connection=nil;
    if ([[self subviews] count]>0) {
        //then this must be another image, the old one is still in subviews
        [[[self subviews] objectAtIndex:0] removeFromSuperview]; //so remove it (releases it also)
    }

    //make an image view for the image
    UIImageView* imageView = [[[UIImageView alloc] initWithImage:[UIImage imageWithData:data]] autorelease];
    //make sizing choices based on your needs, experiment with these. maybe not all the calls below are needed.
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    imageView.autoresizingMask = ( UIViewAutoresizingFlexibleWidth || UIViewAutoresizingFlexibleHeight );
    [self addSubview:imageView];
    imageView.frame = self.bounds;
    [imageView setNeedsLayout];
    [self setNeedsLayout];
    activityOnCell.hidden=YES;

    [data release]; //don't need this any more, its in the UIImageView now
    data=nil;
}
  • 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-04T05:32:35+00:00Added an answer on June 4, 2026 at 5:32 am

    Loading images into a TableView is a common problem. So much so that there are drop in solutions. You are better off using one of these then trying to design your own. You will save a lot of time, usually find an optimized solution and you can always subclass if you need more features.

    reloading the table everytime a new image comes in isn’t the best solution. As when you reload if the user is scrolling he loses his position.

    use https://github.com/AFNetworking/AFNetworking

    Here is how easy it is to do what you need.

    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 100.0f, 100.0f)];
    
    [imageView setImageWithURL:[NSURL URLWithString:@"http://i.imgur.com/r4uwx.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder-avatar"]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to downloading more then 600 images in loop with a progress
I am downloading images from server and saving them locally in my iphone,But sometimes
I am downloading images from URL, but there are spaces in URL so its
I am downloading images using the NSURLConnection sendSynchronousRequest method and that works fine. However,
I'm downloading the images from the online image for cache when offline. When I
For downloading a number of images I'm making DownloadDataAsync calls to separate instances of
In my code, I am downloading all of the images in the beginning of
I have a method that asynchronously downloads images. If the images are related to
I was previously downloading images for my app by using dataWithContentsOfURL to download a
I need to scrape some websites, and would like to avoid downloading images from

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.