Firstly, I would like to ask about your code.
Besides, in this case, I will do like this pattern.
@property (nonatomic) NSInteger remainingTime;
@property (nonatomic) NSTimer *timer;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
- (void)timerAction {
if (!countingFinish) {
remainingTime --;
//backend regular action
[self frontEndUpdate];
}else {
[timer invalidate];
}
}
- (bool)countingFinish {
return (reamainingTime <= 0);
}
- (void)frontEndUpdate {
//update time label, or other front end update action
}
- (void)addCountingRemaining:(NSInteger) _sec {
remainingTime += _sec;
[self frontEndUpdate];
}
btw, this is juz draft code. hope it helps
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…