[英]Block in serial dispatch queue not executing - GCD iOS Objective-C
我有一個for循環將塊排隊到主隊列上,如下所示:
for (int x=0; x<5; x++) {
double delayInSeconds = x * .03;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
... code here ...
}
}
僅第一個塊被執行。 我已經驗證了循環工作正常,正在循環正確的次數,並且沒有引發異常或錯誤。
使用此代碼:
for (int x=0; x<5; x++) {
double delayInSeconds = x * .03;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
NSLog(@"Blah!!");
});
}
“ Blah”被注銷5次。 我猜您發布的代碼與應用程序中的代碼不同? 我必須添加); 到dispatch_after調用的末尾。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.