简体   繁体   English

NSOperationQueue感觉比在主线程上运行代码慢

[英]NSOperationQueue feels slower than running code on main thread

I'm making a tweak (that displays some images from web) for ios and i'm trying to use NSOperationQueue . 我正在为ios进行调整(显示来自Web的一些图像),并且尝试使用NSOperationQueue First i ran some code on the main thread to see how it looks like. 首先,我在主线程上运行了一些代码,以查看其外观。 It lasted ±5secs to show each image (UI froze). 持续±5秒才能显示每个图像(UI冻结)。 Then i tried to use NSOperationQueue to run the same code but it lasted +10secs for each image (good thing is that the UI didn't freeze). 然后,我尝试使用NSOperationQueue来运行相同的代码,但每个图像持续了+10秒(好消息是UI不会冻结)。 Any ideas? 有任何想法吗? Is it just like that? 就是那样吗

In iOS the UI updation takes place on main thread, so once you are done with the operation queue you will need to inform main thread to update UI, but in your case as you said its updated but with delay. 在iOS中,UI更新是在主线程上进行的,因此在完成操​​作队列后,您将需要通知主线程更新UI,但对于您而言,正如您所说的那样,更新是有延迟的。

You will need to call performSelectorOnMainThread:withObject:waitUntilDone: from the operation(in the end, when data is downloaded), and in this main thread's selector you will perform UI updation. 您将需要从操作中调用performSelectorOnMainThread:withObject:waitUntilDone:最后,在下载数据时),然后在此主线程的选择器中执行UI更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM