lazyload images on the iphone - iphone

Does anyone know of a good tutorial that shows how to lazy load images in a UITableView? I've searched online but the only one I found that looked like it did what I wanted was hard to follow because only parts of the code were shown and I'm new at this so I didn't understand how to hook everything up.

I suggest you check out the SDWebImage project on github, I use it for my table views when I need to load a remote image into the cells.
https://github.com/rs/SDWebImage

As Daniel suggested SDWebImage https://github.com/rs/SDWebImage, I don't know of any tutorial, but in amongst the KTPhotoBrowser samples there is one that uses SDWebImage that can show you how to do it https://github.com/kirbyt/KTPhotoBrowser/tree/master/src/Sample/Classes/SDWebImageSample
If I remember correctly you need to import and use the SDWebImage UIImageView category and then pass the url to the cell and call
setImageWithURL:[NSURL URLWithString:#"yoururl"] placeholderImage:[UIImage imageNamed:#"placeholder.png"]
when setting the cell image.

I haven't actually followed it, but this one has plenty of positive commentary: http://www.markj.net/iphone-asynchronous-table-image/

Related

Lazy loading iPhone images

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.

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

How to swap the images in UIImageView programmatically

Hi i am beginner in iphone programming i am doing a photo gallery app. In which i need to apply swapping of array of images on UIImageView along with zooming action.
can any one help me to do this by providing any sample codes or links..
download try this code, i'm using it and it's well done:
mwaterfall-MWPhotoBrowser
there's also the more complete Three20 Photo (search in github.com or in stackoverflow.com for old question), it has more kind of objects... but is also more complicated to be used...

TTStyledTextLabel loading a web image inside a UITableViewCell

I have TTStyledTextLabel inside a UITableViewCell. The label loads a HTML string with references to web image resources. The problem I am facing is that once the image has been loaded the dimensions of the label need to be changed and hence the UITableViewCell.
Any idea as to how this should be done.
Would appreciate any help. This has consumed a lot of my time.
Here is how I did it.
I scanned for all the text to see what images have to be downloaded. Once the images have been identified, i initiated their download using TTURLRequest. After the images were downloaded the sizeThatFits api returns the correct height.
This way is a bit slow, but solves the problem, until I am able to figure out a better way.