带有图像caching和“拉取更新”选项的表格视图

几乎每个iOS应用程序现在都有“Feed”选项。 编程通常包括从网页中获取图片,caching图片,处理页面,“拉取更新选项”等等 – 所有标准的东西。

但看起来像没有标准的解决scheme呢?

  • 我尝试了“三个20” – 真的很大,很多模块复杂的库。 它真的缺乏良好的文档! 从caching中获取图像时,它也有“减速”。

  • 也许我应该为每个小任务分别使用不同的小型图书馆? 像HJCache,EGO等

  • 还是从头开始编写所有的东西而没有任何库?

请给我这里的最佳做法build议,我现在真的卡住了。

这一个很容易放下来刷新。

对于图片加载,我为UIImageView编写了以下类别:

// .h @interface UIImageView (UIImageView_Load) - (void)loadFrom:(NSURL *)url completion:(void (^)(UIImage *))completion; @end // .m #import "UIImageView+Load.h" #import <QuartzCore/QuartzCore.h> @implementation UIImageView (UIImageView_Load) - (void)loadFrom:(NSURL *)url completion:(void (^)(UIImage *))completion { NSURLRequest *request = [NSURLRequest requestWithURL:url]; [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { if (data) { self.image = [UIImage imageWithData:data]; if (completion) completion(self.image); } }]; } @end // To use it when building a cell //... MyModelObject *myModelObject = [self.myModel objectAtIndex:indexPath.row]; if (myModelObject.image) { cell.imageView.image = myModelObject.image; } else { NSURL *url = [NSURL urlWithString:myModelObject.imageUrl]; [cell.imageView loadFrom:url completion:^(UIImage *image) { // cache it in the model myModelObject.image = image; cell.imageView.image = image; }]; } // ... 

我是Leah Culver的Pull to Refresh库的粉丝,或者是这个STableViewController ,它处理拉到刷新以及向下滚动。

对于图像加载, 请从DailyMotion应用程序尝试SDWebImage 。