Objective-C冻结的GUI也带有队列 [英] Objective-C freezed GUI also with queue
本文介绍了Objective-C冻结的GUI也带有队列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试了解iOS中的队列;用此代码
I'm trying to understand queue in iOS; with this code
dispatch_queue_t coda_thread=dispatch_queue_create("coda_thread",NULL);
//UIPROGRESS VIEW
for(i=0;i<=10;i=i+1)
{
dispatch_async(coda_thread,
^{
NSLog(@"CODA_THREAD");
NSLog(@"attendo..");
[NSThread sleepForTimeInterval:10];
dispatch_async(dispatch_get_main_queue(),
^{
NSLog(@"MAIN THREAD");
NSLog(@"aggiorno barra..");
[self.upv setProgress:i/10 animated:YES];
});
});
}
我希望GUI中不会冻结,因为睡眠在coda_thread(而不是在更新GUI的主队列中)队列中,而setProgress在主队列中.
I expected no freeze in GUI because sleep is in coda_thread (and not in main queue where is updated the GUI) queue while setProgress in main queue.. Instead I have freeze in my GUI..why this?
推荐答案
问题是调度队列不是新线程.您不能保证调度队列实际上正在使用其他线程.将GCD API与线程API结合使用是行不通的.
The problem is that a dispatch queue is not a new thread. You have no guarantee that the dispatch queue is actually using a different thread. Combining GCD API with thread API just won't work.
这篇关于Objective-C冻结的GUI也带有队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文