iOS多图下载案例(一)

没有优化前

#import"ViewController.h"

#import"App.h"

@interfaceViewController()

@property(nonatomic,strong)NSArray*apps;

@end

@implementationViewController

- (NSArray*)apps{

if(_apps==nil) {

NSArray*ary = [NSArrayarrayWithContentsOfFile:[[NSBundlemainBundle]pathForResource:@"apps"ofType:@"plist"]];

NSMutableArray*ary1 = [NSMutableArrayarray];

for(NSDictionary*dicinary) {

[ary1addObject:[AppappWithdic:dic]];

}

_apps= ary1;

}

return_apps;

}

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{

returnself.apps.count;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{

return1;

}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{

staticNSString* ID =@"app";

UITableViewCell*cell =[tableViewdequeueReusableCellWithIdentifier:ID];

App*app =_apps[indexPath.row];

cell.textLabel.text= app.name;

cell.detailTextLabel.text=app.download;

//下载图片

NSURL*url = [NSURLURLWithString:app.icon];

NSData*imageData = [NSDatadataWithContentsOfURL:url];

UIImage*image = [UIImageimageWithData:imageData];

cell.imageView.image=image;

returncell;

}

//UI很不流畅-》开子线程下载

//图片重复下载-》缓存

@end

#import

@interfaceApp :NSObject

@property(nonatomic,strong)NSString*name;

@property(nonatomic,strong)NSString*icon;

@property(nonatomic,strong)NSString*download;

+(instancetype)appWithdic:(NSDictionary*)dic;

@end

#import "App.h"

@implementation App

+(instancetype)appWithdic:(NSDictionary *)dic{

App *app = [[App alloc]init];

//KVC

[app setValuesForKeysWithDictionary:dic];

return app;

}

@end

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 概述在iOS开发中UITableView可以说是使用最广泛的控件,我们平时使用的软件中到处都可以看到它的影子,类似...
    liudhkk阅读 9,090评论 3 38
  • *7月8日上午 N:Block :跟一个函数块差不多,会对里面所有的内容的引用计数+1,想要解决就用__block...
    炙冰阅读 2,547评论 1 14
  • 前言 最近忙完项目比较闲,想写一篇博客来分享一些自学iOS的心得体会,希望对迷茫的你有所帮助。博主非科班出身,一些...
    GitHubPorter阅读 1,453评论 9 5
  • 一代风华董鄂妃,才貌双全世皆羡。 与君结缘是天意,三千宠爱在一身。 得君恩爱已满足,更喜爱...
    钰5阅读 603评论 5 6
  • 因跟公司小日本主管意见不合又受到他的排挤,感到工作不顺心就辞了日本公司的职,然后就只身回到了浦东,由于我有相关资质...
    老马讲故事阅读 17,143评论 1 1