当我更改时间间隔的值时,如何更新我的NSTimer [英] How can I update my NSTimer as I change the value of the time interval

查看:124
本文介绍了当我更改时间间隔的值时,如何更新我的NSTimer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了 NSTtimer 并且它运行良好。我还将时间间隔参数连接到 UISlider ,用于 iPhone 。但是,当我更改它的值时, NSTimer 仍然以原始时间间隔运行,它不会更新。我如何实现 NSTimer 并让它改变它的时间间隔,因为我的 UISlider 的值发生了变化。以下是我用于 NSTimer 的行。

I have an NSTtimer implemented and it's working fine. I also have the time interval argument connected to a UISlider for the iPhone. However when I change it's value the NSTimer is still running at the original time interval it does not get updated. How can I implement an NSTimer and have it change it's time interval as the value of my UISlider changes. Below is the line I am using for the NSTimer.

[NSTimer scheduledTimerWithTimeInterval:mySlider.value 
                                 target:self 
                               selector:@selector(myMethod) 
                               userInfo:nil 
                                repeats:YES];

我希望它能够使用 UISlider的值不断更新它的时间间隔

推荐答案

你不能害怕。使其无效:

You can't I'm afraid. Invalidate it with:

[myTimer invalidate];

然后使用新时间创建一个新的。您可能还必须先将其设置为nil。

Then create a new one with the new time. You may have to set it to nil first as well.

myTimer = nil;
myTimer = [NSTimer scheduledTimerWithTimeInterval:mySlider.value 
                                           target:self 
                                         selector:@selector(myMethod) 
                                         userInfo:nil 
                                          repeats:YES];

这篇关于当我更改时间间隔的值时,如何更新我的NSTimer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆