iOS中使用了MZTimerLabel做为计时器添加到任务中,然后使用dispatch_apply来重复执行任务,但计时器无法计时,而且不时在MZTimerLabel中实现的start方法中崩溃 [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
以下是我的代码,timer是引用MZTimerLabel中的第三方,可以在GitHub搜到。
BLOCK myBlock = ^(size_t size){
//如果是单词模式
if (self.typer ==2) {
[timer2 setCountDownTime:[self.timeCount integerValue]*60/2];
[timer2 start];
[timer2 startWithEndingBlock:^(NSTimeInterval countTime) {
[self showView];
}];
}else{
[timer2 setCountDownTime:[self.timeCount integerValue]*60];
[timer2 start];
[timer2 startWithEndingBlock:^(NSTimeInterval countTime) {
agolab.text = @"休息时间";
if([self.rest integerValue]!=0){
[timer2 start];
[timer2 setCountDownTime:[self.rest integerValue]*60];//休息时间
[timer2 startWithEndingBlock:^(NSTimeInterval countTime) {
agolab.text = @"已完成";
}];
}
}];
}
NSLog(@"执行次数");
};
//周期,多次执行的话
if ([self.count integerValue] !=0) {
dispatch_async(dispatch_get_global_queue(0, 0), ^{
dispatch_apply([self.count integerValue], dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), myBlock);
});
}
不負責任的猜測:'startWithEndingBlock:' 是不是會開啟計時器,不需要另外呼叫 'start' ?