ios-nstimer-pause-Pause-Reference loop

Source: Internet
Author: User

Nstimer, is a love and hate class, easy to use, but casually may refer to the loop, memory leaks naturally needless to say;

How convenient to use Nstimer, here a small summary of the next, write the wrong welcome point.

The first is the habit problem, in order to prevent write wrong, I usually put nstimer related to a separate function inside.

As follows:

-(void) inittimer{    if(_timer)    {        [self cleartimer];    }     = [Nstimer scheduledtimerwithtimeinterval:1  target:self selector: @selector (Test) Userinfo:nil repeats: YES];} -(void) cleartimer{    [_timer finalize];     = Nil;} -(void) test{    NSLog (@ "timer! ");}

Also, you can try the initialization once and use it until Dealloc is released, so you need to pause it.

Here's how:

-(void) stratanimationtimer{    -(void) pauseanimationtimer{    [_ Animationtimer setfiredate:[nsdate distantfuture];}

Set the trigger time [NSDate distantfuture], paused, how to pause, trigger time distantfuture, do not understand their translation to ~ ~ ~

How to get started? [NSDate Date], immediately trigger it!

ios-nstimer-pause-Pause-Reference loop

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.