आप आलसी लोड करने के लिए SDWebImage
https://github.com/rs/SDWebImage का उपयोग कर सकते। आप इसे UICollectionView
के साथ प्रभावी ढंग से उपयोग कर सकते हैं।
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
/*---------
----Other CollectiveView stuffs------
-----------------*/
if([[NSFileManager defaultManager] fileExistsAtPath:YOUR_FILE_PATH isDirectory:NO])
{
imagView.image=[UIImage imageWithContentsOfFile:YOUR_FILE_PATH];
}
else
{
UIActivityIndicatorView *act=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[imagView addSubview:act];
act.center=CGPointMake(imagView.frame.size.width/2, imagView.frame.size.height/2);
[act startAnimating];
__weak typeof(UIImageView) *weakImgView = imagView;
[imagView setImageWithURL:[NSURL URLWithString:REMOTE_FILE_PATH] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType){
for(UIView *dd in weakImgView.subviews)
{
if([dd isKindOfClass:[UIActivityIndicatorView class]])
{
UIActivityIndicatorView *act=(UIActivityIndicatorView *)dd;
[act stopAnimating];
[act removeFromSuperview];
}
}
NSString *extension=[YOUR_FILE_PATH pathExtension];
[self saveImage:image withFileName:YOUR_FILE_PATH ofType:extension];
}];
}
}
स्रोत
2014-01-09 11:08:17
बस: क्यों dequeueReusableCellWithReuseIdentifier है: forIndexPath: पर्याप्त नहीं? क्या वह पहले से आलसी लोडिंग नहीं है? मैंने सोचा कि सेल इस विधि के ठीक बाद प्रदर्शित होगा। – Masa
@ मासा यह "आलसी लोडिंग" की तरह है, लेकिन कल्पना करें कि आपके पास 2208x1242 पिक्सल पर एक पूर्णस्क्रीन छवि थी और आप केवल एक दृश्यमान छवि को एक http कनेक्शन की अनुमति देना चाहते थे। 'cellForItemAtIndexPath' कई बार आग लग जाएगा, यह मूल रूप से prefetching है, आलसी लोडिंग नहीं। एफवाईआई: यह प्रतिनिधि आईओएस 8 https://developer.apple.com/library/IOs/documentation/UIKit/Reference/UICollectionViewDelegate_protocol/index.html#//apple_ref/occ/intfm/UICollectionViewDelegate/collectionView:willDisplayCell:forItemAtIndexPath में उपलब्ध है: –