Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For sure you want to download your images lazily and asynchronously as described by other answerers.</p> <p>You also probably want to resize it to your thumbnail size and store it in memory at the smaller size. See <a href="http://vocaro.com/trevor/blog/2009/10/12/resize-a-uiimage-the-right-way/" rel="nofollow">this article</a> for tutorial and actual usable library code to do that (scroll down past the rant about copy-and-paste development).</p> <p>EDIT: You clearly need more help with the background download part. Here's how I do it.</p> <p>Install <a href="http://allseeing-i.com/ASIHTTPRequest/Setup-instructions" rel="nofollow">ASIHTTPRequest</a>, which is a third party library that GREATLY simplifies HTTP client work. Follow the instructions to install it in your project, and make sure you put <code>#include "ASIHTTPRequest.h"</code> at the top of your .m file.</p> <p>Then in your <code>tableView: cellForRowAtIndexPath:</code>, go:</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; if(!cell) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier] autorelease]; UIImageView *myImage = [[UIImageView alloc]initWithFrame:CGRectMake(6,10,58,60)] ; [cell.contentView addSubview:myImage]; [myImage release]; } // so at this point you've got a configured cell, either created fresh // or dequeued from the table's cache. // what you DON'T have is a pointer to the uiimageview object. So we need to // go get it. UIImageView *theImageView; for (UIView *view in cell.contentView.subviews) { if ([view isKindOfClass:[UIImageView class]) { theImageView = view; break; } } NSURL *url = [NSURL URLWithString:[(Tweet*)[tweetArray objectAtIndex:indexPath.row] image_url]]; //here Tweet is other class and image_url is method in the Tweet class ASIHTTPRequest *req = [ASIHTTPRequest requestWithURL:url]; [req setCompletionBlock:^{ NSData *data = [req responseData]; // This is the UIImageView we extracted above: [theImageView setImage: [UIImage imageWithData:data]]; }]; // this will start the request in the background, and call the above block when done. [req startAsynchronous]; } // Then return the cell right now, for the UITableView to render. // The image will get filled in later when it returns from the server. return cell; } </code></pre>
 

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