Change NSTimer interval after a certain number of fires

前端 未结 3 1416
死守一世寂寞
死守一世寂寞 2021-01-26 14:48

In the following code, the NSTimer interval is set at 1 second between each picture. My goal is to change the interval after the first two pictures, hello.png and b

3条回答
  •  不要未来只要你来
    2021-01-26 15:05

    my goal is to change the interval

    You cannot change a timer in any way. To change the firing interval, invalidate and destroy the timer and make a new timer with the new interval.

    To do that, you will need to have kept a reference to the timer, as a property of your view controller (something that you have fatally failed to do in your implementation - you would have had no way to stop the timer, and you would have crashed if your view controller ever went out of existence, or else your view controller would have leaked because the timer retains it).

提交回复
热议问题