문제

Hi I want to create an NSDate object with the following functionality as the NSTimer line below.

[NSTimer scheduledTimerWithTimeInterval:(slider.value * 60) target:self selector:@selector(nextFunction) userInfo:nil repeats:NO];

So what is it that appeals to me about the above like is that I can put in the time I want for it to countdown. Also once the timer has reached 0 the nextFunction method is called. But I need to use NSDate for a future operation that cannot be completed with NSTimer. In summary, I want to create an NSDate that will countdown from whatever current value my slider holds then upon completion of countdown to call the nextFunction method. Thanks

도움이 되었습니까?

해결책

You could create the NSDate from the sliders value:

NSDate *date = [[NSDate alloc] initWithTimeintervalSinceNow:(slider.value * 60)];

Then use its timeInterval to create the timer:

[NSTimer scheduledTimerWithTimeInterval:[date timeIntervalSinceNow] target:self selector:@selector(nextFunction) userInfo:nil repeats:NO];

I guess that should do it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top