試圖創建一個倒數計時器達到某個日期,但我希望它顯示的東西在幾天,而不是月,天(喜歡,2個月的2Days)我寧願只是讓它顯示實際天數像「62天「我應該在代碼中更改什麼?謝謝。如何獲得倒數計時器以顯示倒數天數?
下面是我用於CountDown的代碼。
#import "CountdownViewController.h"
@interface CountdownViewController()
@end
@implementation CountdownViewController;
-(void)updateLabel;
{
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
char units = NSDayCalendarUnit;
NSDateComponents *components = [calendar components:units fromDate:[NSDate date] toDate:destinationDate options:0];
[dateLabel setText:[NSString stringWithFormat:@"%dDays", [components day]]];
}
- (void)viewDidLoad
{
[super viewDidLoad];
destinationDate = [NSDate dateWithTimeIntervalSince1970:1356393600];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
// Do any additional setup after loading the view, typically from a nib.
}
問題是,它只是顯示我的日子部分。我的代碼打以上到達的代碼,但它曾經是這樣
-(void)updateLabel;
{
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
char units = NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [calendar components:units fromDate:[NSDate date] toDate:destinationDate options:0];
[dateLabel setText:[NSString stringWithFormat:@"%d %d %d %d %d", [components month], [components day], [components hour], [components minute], [components second]]];
}