Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to do something like this:</p> <p>1) First create and mutable array full of NSNull.</p> <p>2) On CellForRowAtIndexPath, ask if the array at that indexPath.row is equal to NSNull.</p> <p>2.1) If is equal, download the image like this:</p> <pre><code>dispatch_queue_t bgqueue = dispatch_queue_create("com.yourApp.yyourclass.bgqueue", NULL); dispatch_async(bgqueue, ^{ NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://feature.site.com%@",entry.avatarUrl]]]; UIImage *imageField = [[UIImage alloc] initWithData:imageData]; dispatch_async(dispatch_get_main_queue(), ^{ [imageArray addObject:imageField atIndex:indexPath.row]; tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone] }); }); dispatch_release(bgqueue); </code></pre> <p>2.2) If is not equal(have an Image) just set the image in the array.</p> <pre><code>photo.image = [imageArray objectAtIndex:indexPath.row]; </code></pre> <p>By Doing this your images keep cell order and you increase the performance of the scrolling.</p> <p>PD-1: You should use a library that handles the download and caching of the images like HTTPRequest</p> <p>PD-2: In your Did reReceiveMemoryWarning you should do something like this:</p> <pre><code>- (void)didReceiveMemoryWarning { // Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning]; [imagesArray removeAllObjects]; //Fill the array with NSNull's again; } </code></pre> <p>Further Improvement:</p> <p>In the Array you could have 3 states:</p> <ol> <li>NSNull: No Image</li> <li>NewState(EG. some string): Image being downloaded.</li> <li>UIImage: Image Downloaded.</li> </ol> <p>With this you could prevent for downloading several times the same image if you scroll up and down continuously while the images are being downloaded.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload