iOS LazyTableImages的分析

整个Demo中有LazyTableAppDelegate,ParseOperation,AppRecord,IconDownload,RootViewController

LazyTableAppDelegate

发起一个远程请求,获取App列表的xml的数据,保存到成员变量appListData中,用ParseOperation来进行解析,解析完毕,通知LazyTableAppDelegate的RootViewController的table进行reloaddata,在刷新数据的过程中每个cell将根据自己的AppRecord的imageurl值进行IconDownload下载,总体是这个流程,以下再详解下我的理解:


LazyTableAppDelegate 的成员变量

    UIWindow *window;

    UINavigationController *navigationController;

    RootViewController      *rootViewController; //拥有一个TableView,

    NSMutableArray          *appRecords; //appRecords与rootViewController中的entries共享

    NSOperationQueue *queue; //执行xml的解析类ParseOperation,获取每个appRecord的属性值,并且ParseOperation的delegate也是self

    NSURLConnection         *appListFeedConnection; // 1.发起一个远程请求,获取一个xml内容

    NSMutableData           *appListData; // 从appListFeedConnection中获取到的原始数据


appListFeedConnection的delegate=self;所以要实现以下方法:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response;

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error;

- (void)connectionDidFinishLoading:(NSURLConnection *)connection;

2.最重要的是在didFinishLoading方法中,当数据已经收到,需要传给ParseOperation类去解析,把ParseOperation放入queue中执行

在queue中执行的ParseOperation的delegate=self;所以要实现以下方法:

- (void)didFinishParsing:(NSArray *)appList;

3.当收到ParseOperation类解析完毕的通知,就会执行这个方法,这里执行一个方法是

[self performSelectorOnMainThread:@selector(handleLoadedApps:) withObject:appList waitUntilDone:NO];

这个方式是在主线程上调用handleLoadedApps进行UI更新方法reloaddata(UI更新将对Icon进行下载),传递的参数是ParseOperation解析完毕的workingArrays

- (void)parseErrorOccurred:(NSError *)error;


RootViewController有两种情况

a)还在获取xml阶段,tableview中还没数据,用一个placehold占位,

b)当收到reloaddata方法时,就要对enties进行读取,在读取到icon的url时,利用icondownload进行下载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值