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