Мне нужна помощь с UIProgressView.xcode set progressView по дате окончания
Мне нужно обновить мой прогноз прогресса с текущей даты до даты окончания, которую я выбираю.
Этот метод обновляет только метку и показывает, сколько времени осталось до конца круга.
-(void)updateProgressDate {
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int units = NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [cal components:units fromDate:[NSDate date] toDate:destDate options:0];
[_dateLabel setText:[NSString stringWithFormat:@"%d%c %d%c %d%c %d%c %d%c", [components month], 'm', [components day], 'd', [components hour], 'h', [components minute], 'm', [components second], 's']];
}
-(void)viewDidLoad {
destDate = [NSDate dateWithTimeIntervalSince1970:1369342800];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateProgressDate) userInfo:nil repeats:YES];
}
Как я могу реализовать NSDateComponents для UIProgressView?
Благодаря
Обновлено:
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//1369342800
currentDate = [NSDate date];
destDate = [NSDate dateWithTimeIntervalSince1970:1369342800];
timeRemain = [destDate timeIntervalSinceDate:currentDate];
timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateProgressDate) userInfo:nil repeats:YES];
}
-(void)updateProgressDate {
NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
int units = NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
NSDateComponents *components = [cal components:units fromDate:currentDate toDate:destDate options:0];
//[_dateLabel setText:[NSString stringWithFormat:@"%d%c %d%c %d%c %d%c", [components month], 'm', [components day], 'd', [components hour], 'h', [components minute], 'm']];
[_dateLabel setText:[NSString stringWithFormat:@"%dm %dd %dh %dm", [components month], [components day], [components hour], [components minute]]];
[_progDate setProgress:_progDate.progress = timeRemain]; // here i did += -= right now my progress bar filled but that's not right. my circle 24 day until 24 day next month
// как я понимаю, 1% в месяц это 0,03 верно?
NSLog([NSString stringWithFormat:@"Remain time: %dm %dd %dh %dm"], timeRemain);
}
поэтому ярлык srill идет нормально, но индикатор выполнения всегда заполнен.
Где я ошибаюсь?
Благодаря
Спасибо Anoop, Но проблема здесь в этой строке: [_dateLabel SetText: [NSString stringWithFormat : @ "% d% c% d% c% d% c% d% c% d% c", [месяц компонентов], 'm', [день компонента], 'd', [час компонентов], 'h ', [components minute],' m ', [components second],' s ']]; _progDate (my uiprogressview) не может принимать строки. – Anton
@ Антон: проверьте обновление/Изменить –
Спасибо! Я попробую ваше решение и обновит вас. – Anton