How to dynamically load images in iPhone Table

Source: Internet
Author: User

IPhone TableImplementationDynamicLoadImageThe tutorial is described in this article, mainly based on code implementation. Let's take a look at the content.

IPhoneWhen loading the list, if you wait for all the data in the list to be fully loaded and the relevant content is displayedImage, Loading time is relatively long, so the effect for the user is very poor, the following is a detailed implementationDynamicLoadImageMethod:

 
 
  1. -(UITableViewCell *) tableView :( UITableView *) tableView
  2. CellForRowAtIndexPath :( NSIndexPath *) indexPath {
  3. UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: @ "tag"];
  4. If (cell = nil ){
  5. Cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle
  6. ReuseIdentifier: @ "tag"] autorelease];
  7. }
  8. // Table Design
  9. NSDictionary * one = [array objectAtIndex: indexPath. row];
  10. Cell. textLabel. text = [one objectForKey: @ "title"];
  11. Cell. detailTextLabel. text = [one objectForKey: @ "content"];
  12. [NSThread detachNewThreadSelector: @ selector (updateImageForCellAtIndexPath :) toTarget: self withObject: indexPath];
  13. Return cell;
  14. }
  15.  
  16. -(Void) updateImageForCellAtIndexPath :( NSIndexPath *) indexPath
  17. {
  18. NSAID utoreleasepool * pool = [[NSAID utoreleasepool alloc] init];
  19. UIImage * image = [self getImageForCellAtIndexPath: indexPath];
  20. UITableViewCell * cell = [self. tableView cellForRowAtIndexPath: indexPath];
  21. [Cell. imageView into mselecw.mainthread: @ selector (setImage :) withObject: image waitUntilDone: NO];
  22. [Image release];
  23. [Pool release];
  24. }
  25. -(UIImage *) getImageForCellAtIndexPath :( NSIndexPath *) indexPath
  26. {
  27. Id path = [[array objectAtIndex: indexPath. row] objectForKey: @ "image"];
  28. NSURL * url = [NSURL URLWithString: path];
  29. NSData * data = [NSData dataWithContentsOfURL: url];
  30. UIImage * image = [[UIImage alloc] initWithData: data cache: NO];
  31. Return image;
  32. }

Source code: http://easymorse-iphone.googlecode.com/svn/trunk/WelcomePavilion/

Summary:IPhone TableImplementationDynamicLoadImageI hope this article will help you with the introduction of this tutorial.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.