可能重複:
UIScrollView pauses NSTimer until scrolling finishes滾動型螺紋計時器iphone
我有一個滾動視圖和標籤,以顯示倒計時日期。我有倒計時工作,但每當我拖動scrollview上下倒計時停止,但當我釋放我的手指它開始工作了。我知道它與多線程有關。這是我的代碼
-(void) viewdidload
{
timer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
}
-(void)updateLabel {
NSCalendar *calender = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *countdown = [calender
components:(NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit)
fromDate:[NSDate date]
toDate:destDate
options:0];
timerCountDown.text = [NSString stringWithFormat:@"%dday %dh %dm %ds", [countdown day],[countdown hour],[countdown minute],[countdown second]];
}
我試過了,但它沒有工作:( – kevin
檢查我編輯的答案 – Ilanchezhian
我沒有實現任何scrollviewdelegate – kevin