带有ALAsset Block的NSBlockOperation或NSOperation使用ALAsset URL显示照片库图像 [英] NSBlockOperation or NSOperation with ALAsset Block to display photo-library images using ALAsset URL

查看:175
本文介绍了带有ALAsset Block的NSBlockOperation或NSOperation使用ALAsset URL显示照片库图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于我的问题我正在问这个问题在一个显示光学图像有效的方式iPhone 高效的UITableView cellForRowIndexPath方法绑定PhotoLibrary图像

I am asking this question regarding my questions Display photolibrary images in an effectual way iPhone and Highly efficient UITableView "cellForRowIndexPath" method to bind the PhotoLibrary images.

所以我想请求答案不会重复到这个没有阅读详情如下:)

So I would like to request that answers are not duplicated to this one without reading the below details :)

让我们来讨论这个问题,

Let's come to the issue,

我已经详细研究过上述问题,我从操作队列的文档rel =nofollow noreferrer>这里

I have researched detailed about my above mentioned issue, and I have found the document about operation queues from here.

所以我有c使用操作队列通过ALAsset块显示一个示例应用程序以显示七个照片库图像。

So I have created one sample application to display seven photo-library images using operation queues through ALAsset blocks.

以下是示例应用程序详细信息。

Here are the sample application details.

第1步:

在NSOperationalQueueViewController viewDidLoad 方法中,我检索了所有照片 - gallery ALA将网址设置为名为 urlArray的数组

In the NSOperationalQueueViewController viewDidLoad method, I have retrieved all the photo-gallery ALAsset URLs in to an array named urlArray.

第2步:

将所有网址添加到 urlArray if(group!= nil)条件在 assetGroupEnumerator 中将为false ,所以我创建了一个 NSOperationQueue ,然后通过循环创建了七个UIImageView并创建了我的 NSOperation 子类对象,每个对象具有相应的图像视图 URL ,并且将添加到 NSOperationQueue

After all the URLs are added to the urlArray, the if(group != nil) condition will be false in assetGroupEnumerator, so I have created a NSOperationQueue, and then created seven UIImageView's through a for loop and created my NSOperation subclass object with the corresponding image-view and URL for each one and added them in to the NSOperationQueue.

查看我的 NSOperation 子类此处

查看我的实施(VierwController)课程 此处

让我们来解决这个问题。

Let's come to the issue.

它不会一直显示所有七个图像。一些图像丢失了。丢失的顺序多次改变(一次不显示第六和第七次,另一次不显示第二次和第三次)。控制台日志显示无法找到照片图片号。但是,URL已正确记录。

It not displaying all the seven images consistently. Some of the images are missing. The missing order is changing multiple times (one time it doesn't display the sixth and seventh, and another time it doesn't display only the second and third). The console log displays Could not find photo pic number. However, the URLs are logged properly.

您可以看到日志详细信息这里

You can see the log details here.

我班上有错误吗?

另外,当我走的时候通过上面提到的操作队列文档,我读过 NSBlockOperation 。在处理ALAsset块时,是否需要实现 NSBlockOperation 而不是 NSOperation

Also, when I go through the above mentioned operational queue documentation, I have read about NSBlockOperation. Do I need to implement NSBlockOperation instead of NSOperation while dealing with ALAsset blocks?

NSBlockOperation 说明


您用作的类-is同时执行一个或多个块对象
。因为它可以执行多个块,所以块
操作对象使用组语义进行操作;只有当所有
相关块都已完成执行时,操作本身
才算完成。

A class you use as-is to execute one or more block objects concurrently. Because it can execute more than one block, a block operation object operates using a group semantic; only when all of the associated blocks have finished executing is the operation itself considered finished.

怎么能我使用ALAsset块实现 NSBlockOperation 关于我的示例应用程序?

How can I implement the NSBlockOperation with ALAsset block regarding my sample application?

我已经完成了Stack Overflow问题 学习NSBlockOperation 。但是,我不知道用ALAsset块实现 NSBlockOperation !!

I have gone through Stack Overflow question Learning NSBlockOperation. However, I didn't get any idea to implement the NSBlockOperation with ALAsset block!!

推荐答案

您在DisplayImages NSOperation子类中有一行更新UI(DisplayImages.m第54行):

You have a line in your DisplayImages NSOperation subclass where you update the UI (DisplayImages.m line 54):

self.imageView.image = topicImage;

此操作队列在后台线程上运行,我们知道您应该只更新状态主线程上的UI。由于更新图像视图的视图肯定是在更新UI,因此可以通过使用以下方式包装调用来解决此问题:

This operation queue is running on a background thread, and we know that you should only update the state of the UI on the main thread. Since updating the view of an image view is definitely updating the UI, this can be simply fixed by wrapping the call with:

dispatch_async(dispatch_get_main_queue(), ^{
   self.imageView.image = topicImage;
});

这会在主队列上进行异步调用,以使用映像更新UIImageView。它是异步的,所以你的其他任务可以在后台安排,并且它在主队列上运行是安全的 - 这是主线程。

This puts an asynchronous call on the main queue to update the UIImageView with the image. It's asynchronous so your other tasks can be scheduled in the background, and it's safe as it is running on the main queue - which is the main thread.

这篇关于带有ALAsset Block的NSBlockOperation或NSOperation使用ALAsset URL显示照片库图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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