[英]Block in serial dispatch queue not executing - GCD iOS Objective-C
I've got a for loop enqueuing blocks on to the main queue as follows: 我有一个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 ...
}
}
Only the first block gets executed. 仅第一个块被执行。 I've verified that the loop is working properly, it is looping the proper number of times and no exceptions or error are raised.
我已经验证了循环工作正常,正在循环正确的次数,并且没有引发异常或错误。
With this code: 使用此代码:
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" gets logged out 5 times. “ Blah”被注销5次。 I'm guessing the code you posted isn't identical to the code you have in the app?
我猜您发布的代码与应用程序中的代码不同? I had to add the );
我必须添加); to the end of the dispatch_after call.
到dispatch_after调用的末尾。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.