简体   繁体   中英

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 . First i ran some code on the main thread to see how it looks like. It lasted ±5secs to show each image (UI froze). 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). 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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