簡體   English   中英

串行分派隊列中的塊未執行-GCD iOS Objective-C

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM