In the actual development, we will encounter a scene is: With + scheduledtimerwithtimeinterval ... The way the timer object, which acts on the list on the Uiscrollview, has a tentative callback and is very mad at the failure to understand its rationale. After viewing the official documents and the diary of the Great God, I finally figured it out.
There are two ways to create a timer >: +scheduledtimerwithtimeinterval, +timerwithtimeinterval.
The first method of creating a timer (in most cases using this method)
Scheduledtimerwithtimeinterval: The essence of doing two things:
> Created a Timer object
> Registers the timer listener method with the Runloop (running loop) and adds it in the default Nsdefaultrunloopmode mode, which causes the timer to pause when the list is dragged on Uiscrollview.
Nstimer *timer = [Nstimer scheduledtimerwithtimeinterval:1.0 target:self selector: @selector (nextimage) Userinfo:nil Repeats:yes];
You need to manually add the timer to the run cycle in nsrunloopcommonmodes mode, and if the timer does not fail, it will continue to run.
[[Nsrunloop Currentrunloop] AddTimer:self.timer formode:nsrunloopcommonmodes];
The second method of creating a timer
Timerwithtimeinterval: The Timer object created by this method is not added to the run loop by default and needs to be manually registered to Runloop (running loop).
Nstimer *timer = [Nstimer timerwithtimeinterval:1.0 target:self selector: @selector (nextimage) Userinfo:nil Repeats:YES ];
The timer is automatically turned on as long as the timer object is added to the run loop
[[Nsrunloop Currentrunloop] AddTimer:self.timer formode:nsrunloopcommonmodes];
This method only triggers the callback method once.
[Timer fire];
> When the timer is not needed, remember to remove the timer
Disable the timer: Once the timer expires, it can no longer be used, only to recreate a new timer
[Timer invalidate];
Timer = nil;
Seven, the difficulty of the timer