我想在其他线程中显示alertview(在其他线程中有文本到语音)。 简而言之,我想同时调用两种方法,并希望它们能够同时工作和#34;在同一时间。
但在我的情况下,我正在启动alertView,屏幕变暗,没有alertview,另一个线程启动。在另一个线程准备就绪后,我得到蓝色警报视图:
以下是代码,我的问题是:什么相当于 waitUntilAllOperationsAreFinished ..?
dispatch_async(dispatch_get_main_queue(), ^{
[self alertWhileTTS];
});
[[self view] setNeedsDisplay];
[self synthesizeInBackground];
[queue waitUntilAllOperationsAreFinished];
[self setIsSpeaking: false];
[[self view] setNeedsDisplay];
另见帖子:How to multithred correctly? UIAlertView is not displayed, only gray screen
答案 0 :(得分:0)
这解决了我的问题:
[self performSelectorOnMainThread:@selector(alertWhileTTS) withObject:nil waitUntilDone:YES];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) {
[[self view] setNeedsDisplay];
[self synthesizeInBackground];
[queue waitUntilAllOperationsAreFinished];
[self setIsSpeaking: false];
[[self view] setNeedsDisplay];
});