코딩에 익숙하지 않습니다. 용서해주세요!NSDate 메서드 호출
배경 :
나는 일, 시간, 분, 초에 주어진 날짜에 카운트 다운 간단한 레이블 응용 프로그램을 가지고있다. 나는이 사용 NSDate
및 NSTimer
들했다 :
- (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 (즉, 우리는 주어진 날짜에 도달하면) 내가하는 방법은 숨어으로 화재로 얻을 수있는 방법 객체?
사이드 노트 - 왜 당신은'h','m에 대한 '%의 c'를 사용하는 '등의 형식 문자열로? 콜론처럼 형식 문자열에 문자를 넣기 만하면됩니다. – rmaddy