2

Possible Duplicate:
Lazy load images in UITableViewCell

Ive got a problem with my UITableView cells and it is that my cells are reloading each time they go out from the screen. My app loads images from a url and place them in a ImageView in the left part of the cell, so it makes the UITableView scroll really slow.

I was wondering if there is a way to:

1.Load all the cells at once. 2.Disable the reload of the cells.

In this way the TableView could scroll smoothly. Each cell is composed of three subViews. Two are used for the title and description label and the last one for the image. The contents come from a NSXMLParse so loading this cells takes time.

Thanks in advance.

Community
  • 1
  • 1
Lord Pepito
  • 291
  • 3
  • 15
  • 1
    Possible duplicate of any of the following: [Lazy load images in UITableViewCell](http://stackoverflow.com/questions/531482/lazy-load-images-in-uitableviewcell), [Lazy Loading of several images in UITableView](http://stackoverflow.com/questions/11583108/lazy-loading-of-several-images-in-uitableview), [Lazy load images in UITableView](http://stackoverflow.com/questions/1130089/lazy-load-images-in-uitableview). Found in those questions is this [Apple sample app](https://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html) – Simon Goldeen Jan 04 '13 at 01:24
  • Thanks I will review this questions. – Lord Pepito Jan 04 '13 at 01:29

2 Answers2

3

The three ways I can think of to improve the scrolling are to:

  1. Not load the images in the main thread, just stick in a place holder and have them filled in when the data finally becomes available (lazy loading as mentioned in the comment).

  2. Cache the images yourself so when the cell is viewed later you already have the data to display.

  3. Pre-fetch anticipated images into your cache for the cells above and below the displayed rows.

Of course these are not mutually exclusive and should likely be combined to get the smoothest user interface.

LavaSlider
  • 2,494
  • 18
  • 29
  • Thank you I will give it a try. I was just looking a point to begin my search, now I have a specific idea of what I should do. – Lord Pepito Jan 04 '13 at 01:41
  • At WWDC an Apple engineer stated that to get smooth scrolling in a table view, everything that is done in the cellForRowAtIndexPath method must take less than 16ms. The fact that you're loading data from a URL will almost always take more than 16ms, even on a wifi network. As LavaSlider suggested, do those URL loads on a background thread and load the image asynchronously. NSURLConnection has a very nice helper method that takes a code block that gets executed once the URL data is loaded. That may make things easier to implement in this case. – Jack Cox Jan 04 '13 at 02:21
3

Instead of using uiimageview use sdwebimage. It will help you I think.

Exploring
  • 925
  • 6
  • 18
  • Thanks a lot. This library made the differnce. Easy to implement and the best part is that it works perfectly no more delay during the early phase of the TableView and no delay during the scrolling. This library was the perfect solution for this kind of problem. – Lord Pepito Jan 04 '13 at 04:51