0
剛開始使用ReactiveCocoa並慢慢轉換當前代碼以使用它。ReactiveCocoa倒計時
現在我有一個倒計時日期計時器完成,只是我不知道如何停止計時器倒計時完成後,做完成另一個動作。
NSTimeInterval dateInSecond = 1440855240;
self.dateUntilNextEvent = [NSDate dateWithTimeIntervalSince1970:dateInSecond];
RACSignal *countdownSignal = [[[[RACSignal interval:1 onScheduler:[RACScheduler schedulerWithPriority:RACSchedulerPriorityBackground]]
startWith:[NSDate date]] map:^id(NSDate *value) {
if([self.dateUntilNextEvent earlierDate:value] == self.dateUntilNextEvent){
//Stop "timer" and call an onComeplete method
return @"0";
}
NSUInteger flags = NSDayCalendarUnit
| NSHourCalendarUnit
| NSMinuteCalendarUnit
| NSSecondCalendarUnit;
NSDateComponents *components = [[NSCalendar currentCalendar] components:flags
fromDate:value
toDate:self.dateUntilNextEvent options:0];
return [NSString stringWithFormat:@"%02ld : %02ld : %02ld : %02ld",
(long)[components day], (long)[components hour],
(long)[components minute], (long)[components second]];
}] deliverOn:RACScheduler.mainThreadScheduler];
RAC(self.countdownLabel,text) = countdownSignal;
任何幫助將appriciated,或只是哪個方向去!
令人驚歎的,感謝您的幫助和保留週期問題提示! :) – mario