UITableView got slowly when dragging - iphone

I am new to iPhone development, and I can not understand the working principle of UITableView well.
I customize the UITableViewCell, and the cell contains imageview. In addition, I initialize the cell reusable. However, when I drag the UITableView, it scrolls slowly.
Then what should I do to process it?

If you are loading images from your applications bundle you can increase the scroll speed by making the images the exact size they need to be to fit in the UITableViewCell imageView so the device doesn't have to size them on the fly. Do this by adding smaller versions of the images in your applications bundle, or by resizing them in code as needed in a background thread.
Alternatively if this solution won't work for you, or you are loading images from the internet have a look at Lazy loading images in UITableView, a process where images are only loaded when needed and can be downloaded asynchronously.
Alternatively, you can use a prebuilt class to do your image downloading, caching and lazy loading for you like TTImageView or SDWebImage.

Related

Load more images in UITableView with images using lazy loading

I have a UITableView with images like photo album, images are loading with lazy loading. I want to load more images while scrolling to the bottom of the tableview or when the last row of the table view reached. How can I do this?
UITableView already does lazy loading for you. It will only ask for the visible cells. If you are taking about adding more images to the table while the user is scrolling, you can implement UIScrollViewDelegate methods to calculate the current scrolling position, and when the user reaches certain point, add more images to the NSMutableArray on your datasource.
Check this
http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html
and this Lazy load images in UITableView
You can use SDWebImage.
This library provides a category for UIImageVIew with support for remote images coming from the web.
It provides:
An UIImageView category adding web image and cache management to the Cocoa Touch framework
An asynchronous image downloader
An asynchronous memory + disk image caching with automatic cache expiration handling
A guarantee that the same URL won't be downloaded several times
A guarantee that bogus URLs won't be retried again and again
Performances!

iPhone - UITableView reload on scrolling

I've a UITableView and each UITableViewCell displays a unique UIImage which is fetched from internet. As we scroll the UITableView, cells are recreated and tableView: cellForRowAtIndexPath: gets called every time to configure cells. So it loads UIImages again and again from internet and scrolling is not smooth.
The solution I found for myself right now is to create NSMutableArray of all those UIImages on ViewDidLoad then load images into UITableViewCells from that NSMutableArray which is for sure giving me smooth scrolling.
My concern with my own solution is that when I keep all UIImages in NSMutableArray and those all objects are kept in memory for as long as application runs, I am most probably making inefficient use of memory.
Is there a better, more efficient way to do this which gives me smooth scrolling as well as best memory usage?
I think this example will help you..
http://kosmaczewski.net/2009/03/08/asynchronous-loading-of-images-in-a-uitableview/
Cache the downloaded images on the filesystem. When loading a cell, first ensure that a cached copy of the associated image is available, then load it using [UIImage imageWithContentsOfFile:].
You should go with array of image link instead of the image.
You should load image asynchronously so that it will improve performance of creation of the UITableviewCell.
Verify that you are using dequeueReusableCellWithIdentifier, it will give you the smoother scrolling.

How to load images in UIScrollView asynchronously?

HI,
I am getting my images using JSON and I need to display image at a time when my app is running so please tell me how to use asynchronous method to load the images into the UIScrollView?
Thanks.
whether you use a UITableView or a UIScrollView, you will use the same pattern, its just that you have a bit more plumbing to do with the UIScrollView. I would say use the UITableView unless you want to roll your own multi-column image thumbnail picker.
With the UIScrollView, you will need to create your own virtual rows and columns and detect when the ScrollView has scrolled a new row or a new column into view. You will need to queue (remove) the images that have scrolled out of view, and then load the images that have come into view. All in all, this is not trivial code.
The UITableView does all this for you (rows only, no concept of columns)
Having said that.. here is a reference to using the NSOperation class to lazy load your images into a UITableView while giving the user a smooth experience..
UIImage in uitableViewcell slowdowns scrolling table

Displaying images in UIScrollView programmatically

I am displaying 200 thumb nail images of size 4kb to 12kb in UIScrollView programmatically by adding UIButton when i am debugging in device it takes time to load the view.. can there is some method to load quickly the thumb mages are store in disk.
Use lazy loading by only loading the ones you show at once in any given moment - or use a background thread to perform the loading while keeping the interface responsive.
If your layout allows, use a table view and a custom cell that holds several thumbnails. That way you can use the tableview controller's built in methods to manage the lazy loading. I'm pretty sure that is how Apple does the thumbnails in the photo library.

How to implement UIImageView-like delayed loading in UITableView

Background:
I have a UITableView showing an image in each cell. These images are all part of a big pdf-file. So what I am doing is actually rendering little pdf-parts in those UITableViewCells, each cell displaying just one piece. Therefore I add a UIView to the contentview of the cell and render the view on demand.
Rendering these pdf-parts is expensive and each takes about 0.2 seconds (only drawing the Pdf-part), which slows the scrolling of the table terrible down.
Idea:
Now, I know there may be a solution when I look how UIImage renders URL-based images. If you create a UIImage based on a url, these images are rendered somehow delayed. E.g have a look at the iTunes-App.
Smooth scrolling is possible, each image is displayed unrendered and after rendering is finished it appears smoothly.
Problem: How can I render an expensive rendering in a UITableViewCell like described above, by somehow showing the cell delayed? Has anybody an idea, how Apple solved it within UIImageView?
Thanks in advance
Daniel
this is (mostly) duplicate of Lazy load images in UITableViewCell. Check the links and examples there.
In short, what you need is spawning a separate thread for loading the PDF thumbnails, and that thread then signaling back to the main thread with the generated images. This is easily done by using performSelectorInBackground:withObject: and performSelectorOnMainThread:withObject:waitUntilDone: methods.