How to use Lazy Loading in Paging?
I have a viewController, in that i have used Page control. and each page have 4 imageViews.
I have passed Xml and according to number of images in that i got the number of pages of pageControl that is (NumberOfImages/4).
I have done my code like this...
first i get url of each images and store them in Array..
for(int i=0;i<[Array Count];i++)
{
imgString=[NSString stringWithFormat:@"%@",[Array objectAtIndex:i]];
NSLog(@"string :%@",imgString);
NSString *abc=[imgString tringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
//NSLog(@"abc :%@",abc);
NSURL *url=[NSURL URLWithString:abc];
NSLog(@"url :%@",url);
NSData *data = [NSData dataWithContentsOfURL:url];
[ImageArray addObject:[UIImage ImageWithData:data]];
}
The above code takes time to fetch images from URL.and until all r not开发者_开发知识库 fetched i have to wait..
So i want to use Lazy Loading Here..I have show apple Lazy Loading Example for TableView..but not getting how to use it with Paging??
so can anyone suggest me what can i do for this?? any Help is appreciated..
You could create a Category for the UIImageView class and add some methods that will allow you to do the following:
Load the image from a cache file in the tmp directory - if a cache file can't be found, download the image from the web on a background thread then save it to cache.
By checking for a cache file first you can skip re-downloading the content.
By downloading the image on a background thread your application will not lag while waiting for content to finish loading.
By using a Category, your methods will apply to any UIImageView you want to use - and will even work in paging.
Rather than post a complete code solution here I'm going to suggest that you research and develop your own solution.
Best of luck.
精彩评论