0
我需要按顺序执行一些操作。 有许多对象符合一个协议(有一个方法,即execute())以执行的顺序插入到一个数组中。执行一批操作,并在每个操作的中间有一个用户交互
一切看起来简单使用GCD的东西,如:
dispatch_queue_t serialQuele = dispatch_queue_create("myQueue", NULL);
for (id <ExecutableProtocol> exec in executables)
{
dispatch_async(serialQuele, ^{
[exec executeWithCompletionBlock:^(NSString *name, Status *state) {
[self.executeResults setObject:state forKey:name];
dispatch_async(dispatch_get_main_queue(), ^{
if (self.delegate)
[self.delegate didExecuted: exec withResult:state userInfo:userInfo];
});
}];
});
}
理念看起来不错,但如果执行要求有UIAlertController用户一个问题......接下来的执行也无法显示其对话框,UIAlertController因为用户尚未回答该问题,并且前一个对话框仍在显示。
我该如何达到我的预期?
谢谢。
感谢列弗但像你建议的UI被冻结......上的日志我看到所有的元素都执行,但用户界面停止的第一个元素上,并且用户不能回答,因为一切都冻结。 – jerrygdm
这很奇怪。我很难看出为什么会这样。它会阻止'didExecuted:withResult:userInfo'方法中有'dispatch_sync(dispatch_get_main_queue(),^ {...})'调用,但是我想你已经检查过了。 –
里面didExecuted方法委托有ony一个collectionView的reloadData ... – jerrygdm