Pregunta

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

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top