本文介绍了NSOperationQueue mainQueue vs performSelectorOnMainThread?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这之间有什么区别:
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self doSomthing:object];
}];
并且:
[self performSelectorOnMainThread:@selector(doSomething:) withObject:object waitUntilDone:NO]
推荐答案
[self performSelectorOnMainThread:@selector(doSomething:)
withObject:object
waitUntilDone:NO]
调用时将执行选择器。这是你必须使用,如果你想从后台线程影响UI。如果你说 YES
到 waitUntilDone
,它将阻塞线程,直到方法完成。
Will perform the selector right when it is called. This is what you have to use if you want to affect the UI from a background thread. If you say YES
to waitUntilDone
it will block the thread until the method has completed.
mainQueue
将该块添加到mainthread的操作队列,但不保证何时执行。该队列中可能还有其他项目仍在等待执行。
mainQueue
adds that block to the operation queue of the mainthread but does not guarantee when it will be executed. There could be other items in that queue still waiting to execute.
这篇关于NSOperationQueue mainQueue vs performSelectorOnMainThread?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!