我是新來的編碼,請原諒任何無知!NSDate調用方法
背景:
我有一個倒計時到以天,小時,分鐘和秒給定日期一個簡單的標籤的應用程序。 我這樣做是使用NSDate
和NSTimer
S:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//Countdown timer
destinationDate = [NSDate dateWithTimeIntervalSince1970:1413961418];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateLabel) userInfo:nil repeats:YES];
}
-(void)updateLabel {
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int units = NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [calendar components:units fromDate:[NSDate date] toDate:destinationDate options:0];
[countdownLabel setText:[NSString stringWithFormat:@"%ld%c : %ld%c : %ld%c : %ld%c", (long)[components day], 'd', (long)[components hour], 'h', (long)[components minute], 'm', (long)[components second], 's']];
}
問題:
當倒計時標籤達到0(即當我們到達指定的日期)我怎樣才能得到一個方法來火,如隱藏一個東西?
附註 - 你爲什麼用'%C'的'h','M '等在你的格式字符串?只需將字母放在格式字符串中就像冒號一樣。 – rmaddy