采用多个参数performSelectorOnMainThread [英] performSelectorOnMainThread with multiple parameter
问题描述
我试图执行主线程上这个动作:
I am trying to perform this action on the main thread:
[curItem.mButton setBackgroundImage:newArt forState:UIControlStateNormal];
所以,我这样做...
So I do this...
cWrapperObject* obj = [cWrapperObject alloc];
[obj setupParams :curItem.mButton :newArt];
[obj performSelectorOnMainThread:@selector(setImageForButton) withObject:nil waitUntilDone:YES];
我觉得这是不好的,没有任何人对我怎么能处理这有什么建议不同?
I feel like this is bad, does anyone has any suggestions on how I could approach this differently?
推荐答案
另一种选择是GCD。您可以调用运行循环运行时,它获取连续运行主队列块。块不限于一个对象像performSelectorOnMainThread
Another option is GCD. You can invoke a block on the main queue which gets run serially when the run loop runs. blocks aren't limited to one object like performSelectorOnMainThread.
dispatch_async(dispatch_get_main_queue(), ^{
// code here
});
我写performSelectorXXX和GCD与样品完全在这里的多个COM prehensive比较:
I wrote a more comprehensive comparison of performSelectorXXX and GCD here complete with samples:
<一个href=\"http://stackoverflow.com/questions/7290931/gcd-threads-program-flow-and-ui-updating/7291056#7291056\">GCD,线程程序流和用户界面更新
此外,这里是另一个相关的SO职位:
Also, here's another related SO post:
这篇关于采用多个参数performSelectorOnMainThread的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!