Nstimer not invalidating
However, for a repeating timer, you must invalidate the timer object yourself by calling its [invalidate() ] method.
Calling this method requests the removal of the timer from the current run loop; as a result, you should always call the [invalidate() ] method from the same thread on which the timer was installed.= Selectable Button.button With Type(UIButton Type Custom)do |button| button.style Id = 'timer_button' Title(' Start Timer', for State: UIControl State Normal) Title("Interrupt!" , for State: UIControl State Selected) Target(next Responder, action: 'timer_button_tapped:', for Control Events: UIControl Event Touch Up Inside) end end and you'll see the button background turn to red like so: Once the timer reaches zero, the button background returns to green.Because of the various input sources a typical run loop manages, the effective resolution of the time interval for a timer is limited to on the order of 50-100 milliseconds.If a timer’s firing time occurs during a long callout or while the run loop is in a mode that is not monitoring the timer, the timer does not fire until the next time the run loop checks the timer.
Therefore, the actual time at which the timer fires potentially can be a significant period of time after the scheduled firing time. 总结：nstimer可能不会定时触发 定时时间间隔为2秒，t1秒添加成功，那么会在t2、t4、t6、t8、t10秒注册好事件，并在这些时间触发。假设第3秒时，执行了一个超时操作耗费了5.5秒，则触发时间是：t2、t8.5、t10，第4和第6秒就被跳过去了，虽然在t8.5秒触发了一次，但是下一次触发时间是t10，而不是t10.5。 Repeating Versus Non-Repeating Timers You specify whether a timer is repeating or non-repeating at creation time.