IPhone IOS timer nstimer tutorial

Source: Internet
Author: User

Hope you can support our Website: http://t.cn/zOdAUxJ to raise comments

Nstcoa is a common Timer class in cocoa. The basic operations are as follows:
The handletimer method can be customized. You can create a timer as needed, and handletimer can be executed every 0.5 seconds.

Example:

-(Void) handletimer: (nstimer *) Timer

{// Processing here} nstimer * timer; timer = [nstimer scheduledtimerwithtimeinterval: 0.5 target: Self selector: @ selector (handletimer :) userinfo: Nil repeats: Yes];


Note:

1: If you do not want to cycle timer, change the code

Repeats: No


2. After nstcount initialization, add retaincount of self to 1.

Then, we need to execute [Timer invalidate] before releasing this class; otherwise, the dealloc method of this class will not be executed. 3. When you drag a table ( Stop when uiscrollview is scratched), Timer stopped

- (void)setTimer{NSTimer *timer;NSDate *date = [NSDate date];timer = [[NSTimer alloc] initWithFireDate:date interval:m_ablum.m_displayInterval target:self       selector:@selector(updateTime:) userInfo:nil repeats:YES];[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];self.m_timer = timer;    [timer release];}

Not updated in nsdefaultrunloopmode.

timer = [[NSTimer alloc] initWithFireDate:date interval:m_ablum.m_displayInterval target:self       selector:@selector(updateTime:) userInfo:nil repeats:YES];

When it is set to target, its retaincount plus one .!!!!

Note

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.