0
Я борюсь с обновлением UILabel для отсчитывать для этого я использую следующий кодПроблема в отсчитывать дни часов минут от NSDate
- (void)updateLabel {
// convert date string to date then set to a label
NSDateFormatter *dateStringParser = [[NSDateFormatter alloc] init];
[dateStringParser setDateFormat:@"MM/dd/yyyy"];
NSLog(@"date from update label %@", _selectedBirthdate);
//OUTPUT date from update label 07/23/2013
NSDate *date = [dateStringParser dateFromString:_selectedBirthdate];
NSLog(@"date from update label %@", date);
NSTimeInterval timeInterval = [date timeIntervalSinceNow]; ///< Assuming this is in the future for now.
NSString *stringVariable = [self stringFromTimeInterval:timeInterval];
self.dayLable.text = [NSString stringWithFormat:@"%@", stringVariable];
self.hourLable.text = [NSString stringWithFormat:@"%@", stringVariable];
self.minutesLable.text = [NSString stringWithFormat:@"%@", stringVariable];
// i want to update this day hour minutes lable like this much of days hour and minutes remaining
NSLog(@"%@",stringVariable);
}
Я использую следующий метод для подсчета дней часов и минут, но я не знаю, Что логический ум здесь не работает, как найти дни в часах и минутах от интервала
- (NSString *)stringFromTimeInterval:(NSTimeInterval)interval {
NSInteger ti = (NSInteger)interval;
NSLog(@"%d",ti);
// NSInteger seconds = ti % 60;
NSInteger days = (ti * 60);
NSInteger minutes = (ti/60) % 60;
NSLog(@"%d",minutes);
NSInteger hours = (ti/3600);
NSLog(@"%d",hours);
return [NSString stringWithFormat:@"%02i hours : %02i min", hours, minutes];
}
пожалуйста, проверьте мой ответ это: HTTP: //stackoverflow.com/questions/13505837/count-down-timer-iphone/13506213#13506213 –