Lazy loading iPhone images - iphone

If I would like to have lazy loading like google+ or facebook app (maybe even 9gag), should I go with UITableView or UIScrollView?
The goal is to load whole new set of cells or scrollview pages (not just thumbnail like apple lazyloading tableview). If you have facebook app, try scrolling down fast and you will see what I mean.
Any example would be also helpful.
Thanks.

You should prefer table view for this. with tableview , You can use reusable customcell. tableview can be useful for Auto layout in landscape mode and if app is universal the tableview is more useful.

You can try this: https://github.com/nicklockwood/AsyncImageView. This is a best example for loading images asynchronously. The library can also be used to load and cache images independently of a UIImageView as it provides direct access to the underlying loading and caching classes.

Using Grand Central Dispatch you can do this.
The following link might be useful.
http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial

Take a look at SDWebImage, really easy to use, it support caching and asynchronous loading.

I would use a uicollection view. Here is an example that uses uitableview, but you can take it and modify it a bit to work with a collection view.
http://developer.apple.com/library/ios/#samplecode/LazyTableImages/Introduction/Intro.html
If you would like to use a third party library, I would suggest looking at AFNetworking It's one of the most highly used and has a very easy to use function that extends UIImageView LINK
Also as an FYI, a scrollview is part of a tableview.

Related

LazyTableImages vs SDWebImages

In apple's lazyTableImages project when you first run images appear asynchronusly altough you haven't started scrolling. But in SDWebImage it is not like that. If you don't start to scroll, images don't start to appear. I couldn't succeed to populate LazyTableImages in my project. But i did SDWebImage. So i want to add that functionality as well. Is that possible? I want to download images when new cell is created. I know lazyTableImages does that job but i am not sure that SDWebImages does too. Because when i scroll the table images are already there like they are loaded before.
Thank you for your answers..
Is it possible? Yes. How would you achieve this? It sounds like you should probably look in more detail at both the LazyTableImages sample code and the SDWebImage source. It sounds as if you're maybe just trying to copy/paste a lot of code, and you'll really benefit from understanding how it actually all pulls together and works.
SDWebImage is just a UIImageView category, so is comparativly 'dumb' compares to Apple's sample code, which hooks into the table view's underlying scroll view to detect when you've finished scrolling and load in the cells that are displayed (to make it appear more responsive).
Once you're comfortable with how both those classes are achieving their asynchronous download you'll be in a much better position to start playing around with how they work.

asynchronous image loader in UITableView

Does anyone know any good library/tutorial that can do asynchronous image loading for a cell in UITableView? I am looking for a method that doesn't involve too much code changing in my current code and easy to integrate to a regular synchronous UITableView.
Try looking into Three20
An open source library written by the guy who wrote the official "Facebook" app for iOS.
Moreover, the code of the facebook app is based on that library.
If you rather do it by yourself, read MHLazyTableImages, it comes with a github project. It's an adaptation of Apple's LazyTableImages. Or you can use HJCache.
Fully-Loaded is another one which is pretty simple. It's more a generic image view loaded which you can use in custom table view cells.
https://github.com/foursquare/fully-loaded
I quite like SDWebImage, which is an asynchronous image downloader with cache support with an UIImageView category.
https://github.com/brendanlim/SDWebImage

ScrollView as PhotoViewer, load Images only if needed

I would like to create a PhotoViewer for an iPhone.
For that, I already created a ScrollView with Paging enabled in that I add programmically add the UIImageViews. The problem I see is, that if I would have like 100 Images and I would all add to the ScrollView it would take alot of performance and memory.
How would you make it more performant? I thought about loading the Images of the following 2 pages and releasing the Images after the 2 Images before when scrolling through the pages.
I thought about creating a Subclass of UIScrollView and to name it UIPhotoScroller (or something like that). But I also want to show a UIView in the MainWindow with Information about the Images. Is it possible to make the UIView visible from the Subclass?
You really would help me with that. Thank you in advance :D
Create an NSCache.
When you need a particular image, try to get it from the cache. If it's not there, load it from disk and save it in the cache. The filename is a suitable key.
When you get a memory warning, tell the cache to empty itself.
The cache will release some of its entries periodically, depending on how it's configured. This is a good thing, but you might want to adjust it to have a particular total memory size. Tweak its parameters until it behaves like you want it to. To see your memory usage, use Instruments.
How about doing a UITableView with a single photo per cell. When a cell is being request by the data source, you display a spinner and have a queued NSOperation load the image and refresh the row when done.
You can control the amount of concurrent ops with a NSQueue, so you have complete control on performace/responsiveness. You can then remove old cached images when low on memory/paging, etc.
There are solutions to horizontal UITableView if you need horizontal scrolling.
Have you looked at the three20 library? There's an example of creating a great Photos app-like viewer of photos, and it's pretty easy to work with the three20 library.
Hope this helps!

Iphone - grid of pictures using scroll view and ad UIImageViews to it

Can someone give me one source file working ?
Alternatively you can look at my AQGridView, which can display anything in a grid, using an API similar to that of UITableView.
You might want to take a look at Facebook's Three20, specifically their TTPhotoViewController class.
Update: Other options (possibly more modular and easier to integrate in your project):
https://github.com/mwaterfall/MWPhotoBrowser
https://github.com/kirbyt/KTPhotoBrowser
http://github.com/alanQuatermain/AQGridView (as suggested by Jim)

How to use the Three20 for scrolling

i want to display many images and button on each image in a scroll view. and i want the images loaded which are only visible if the user scrolls i want do load the images dynamically. so can i use the Three20 code how to see the actual code for making tiles
in Three20
Yes, Three20 can do that. If I remember correctly, you need to subclass TTPhotoSource and implement code to load the image on-demand from the server.
Interesting classes regarding internet-aware TableViews are TTTableViewDataSource and TTTableViewController Sorry, can't post links for these. New users like me are limited to one link per post.
You find them on Github too. Just look at the "/src/Three20UI/Headers/"-directory