苹果的LazyTableImages样的问题 - 不完全一样的应用程序商店 [英] Question about Apple's LazyTableImages sample - Doesn't behave exactly like the app store

查看:195
本文介绍了苹果的LazyTableImages样的问题 - 不完全一样的应用程序商店的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有项目的列表的UITableView,每一个具有它自己的图像。我认为苹果的LazyTableImages示例项目将是完美的学习,用于实现同一种异步下载图像,原始列表检索数据后的过程。

在大多数情况下,它工作得很好,但我也注意到在行为上细微的差别,这个示例应用程序之间,以及如何实际应用商店下载的图像。

如果您启动LazyTableImages样品,然后做一个快速轻弹,向下滚动,你会看到的图像没有得到显示,直到的之后的滚动来完全停止。

现在,如果你在实际的应用商店项目的列表做同样的测试,你会看到图像开始为新项目映入眼帘尽快显示,即使滚动仍未停止。

我想实现这些相同的结果,但到目前为止,我没有取得任何进展。有没有人对如何做到这一点任何想法?

谢谢!


解决方案

我百思不得其解,没人能回答这个...

所以,我终于想通了如何acheive的的确切的是在实际的应用程序商店中使用同样的效果,在问候的图标如何下载/显示。

取LazyTableImages示例项目,并提出一些修改simpled


  1. 走进根视图控制器,并删除有关的表滚动和/或减速的cellForRowAtIndexPath所有检查


  2. 删除来loadImagesForOnScreenRows所有呼叫,从而去除方法为好。


  3. 走进IconDownload.m,改变startDownload方法的的做一个异步图像立即下载,而是做在后台线程同步下载。删除所有code在startDownload,并添加以下,所以它看起来是这样的:




- (无效)startDownload
{
    NSOperationQueue *队列= [NSOperationQueue新]
    NSInvocationOperation *操作= [[NSInvocationOperation页头] initWithTarget:自我选择:@选择(的LoadImage)对象:无];    [队列addOperation:操作]。    [操作释放];
    [队列发布]
}

然后,添加一个的LoadImage,像这样的:



- (无效)的LoadImage
{
    NSData的*为imageData = [[NSData的页头] initWithContents OfURL:[NSURL URLWithString:AP precord.imageURLString]];
    self.ap precord.appIcon = [UIImage的imageWithData:为imageData];
    [为imageData发布]    [个体经营performSelectorOnMainThread:@selector(notifyMainThread)withObject:无waitUntilDone:NO];
}

然后,添加notifyMainThread是这样的:



- (无效)notifyMainThread
{
    [委托appImageDidLoad:self.indexPathInTableView];
}

完成!运行它,你会看到确切的应用程序商店的行为,没有更多的等待请求下载图像,直到滚动停止,并没有更多的等待图像显示,直至滚动停止,或直到用户已经从屏幕上删除他们的手指。

作为细胞准备好被显示,并且是只要它被下载所显示的图像

图像一旦下载,周期

对不起任何错别字,我没有从我的应用程序复制粘贴此,我输入它,因为我是从我的MAC离开现在...

无论如何,我希望这有助于大家...

I have a UITableView with a list of items, each having it's own image. I thought Apple's LazyTableImages sample project would be perfect to learn from, and use to implement the same kind of process of downloading images asynchronously, after the original list data is retrieved.

For the most part, it works quite well, except I did notice a subtle difference in behavior, between this sample app, and how the actual app store downloads images.

If you launch the LazyTableImages sample, then do a quick flick-scroll down, you'll see that the images do not get displayed until after the scrolling comes to a complete stop.

Now, if you do the same test with a list of items in the actual app store, you'll see that the images start displaying as soon as the new items come into view, even if scrolling hasn't stopped yet.

I'm trying to achieve these same results, but so far I'm not making any progress. Does anyone have any ideas on how to do this?

Thanks!

解决方案

I'm baffled that nobody could answer this...

So, I eventually figured out how to acheive the exact same effect that is used in the actual app store, in regards to how the icons are downloaded/displayed.

Take the LazyTableImages sample project and make a few simpled modifications.

  1. Go into the root view controller and remove all checks regarding is table scrolling and/or decelerating in cellForRowAtIndexPath

  2. Remove all calls to loadImagesForOnScreenRows, and thus remove that method as well.

  3. Go into IconDownload.m and change the startDownload method to not do an async image downlaod, but instead do a sync download on a background thread. Remove all the code in startDownload, and add the following, so it looks like this:


- (void)startDownload
{
    NSOperationQueue *queue = [NSOperationQueue new];
    NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(loadImage) object:nil];

    [queue addOperation:operation];

    [operation release];
    [queue release];
}

Then, add a loadImage, like this:


- (void)loadImage
{
    NSData *imageData = [[NSData alloc] initWithContents OfURL:[NSURL URLWithString:appRecord.imageURLString]];
    self.apprecord.appIcon = [UIImage imageWithData:imageData];
    [imageData release];

    [self performSelectorOnMainThread:@selector(notifyMainThread) withObject:nil waitUntilDone:NO];
}

Then, add notifyMainThread like this:


- (void)notifyMainThread
{
    [delegate appImageDidLoad:self.indexPathInTableView];
}

Done! Run it, and you will see the exact app store behavior, no more waiting to request image downloads until scrolling stops, and no more waiting for images to display until scrolling stops, or until user has removed their finger from the screen.

Images are downloaded as soon as the cell is ready to be displayed, and the image is displayed as soon as it is downloaded, period.

Sorry for any typos, I didn't paste this from my app, I typed it in, since I'm away from my mac right now...

Anyway, I hope this helps you all...

这篇关于苹果的LazyTableImages样的问题 - 不完全一样的应用程序商店的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆