Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>here is the methodology I use for loading images into a UITableView from a remote location:</p> <p>in your .h file, declare a mutable dictionary for storing the images:</p> <pre><code> NSMutableDictionary *images; </code></pre> <p>initialize the dictionary in -init... or in -viewDidLoad</p> <pre><code>images = [[NSMutableDictionary alloc]init]; </code></pre> <p>in the .m, <code>tableView:cellForRowAtIndexPath:</code>, see if the image exists in your dictionary for the indexPath</p> <pre><code>UIImage *img = [images objectForKey: indexPath]; </code></pre> <p>if the image does exist, just set it.</p> <pre><code>if (img) cell.imageView.image = img; </code></pre> <p>if the image does NOT exist, set the cell's image to a temporary image...</p> <pre><code>if (!img) cell.imageView.image = [UIImage imageNamed:@"imageUnavailable.png"]; </code></pre> <p>AND add that image to your dictionary so it doesnt try to refetch the image if you scroll off and back to that image before it loads...</p> <pre><code>[images setObject:[UIImage imageNamed:@"imageUnvailable.png"] forKey: indexPath]; </code></pre> <p>then, in this same block, use an NSOperationQueue, and a custom NSOperation ( here is a reference - <a href="https://stackoverflow.com/questions/4845088/nsoperation-and-setimage">NSOperation and SetImage</a>) to get your image and call back into your UITableViewController with that image.</p> <p>in your callback, add your image to the dictionary (overwriting the temp image) and call [tableView reloadData]</p> <p>this will give you a nice non blocking user experience.</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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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