Learn about nstimer

Source: Internet
Author: User

Nstimer

 

Create a timer


+ Scheduledtimerwithtimeinterval: Invocation: repeats:

+ (Nstimer *) scheduledtimerwithtimeinterval :( nstimeinterval) Ti invocation :( nsinvocation *) Invocation repeats :( bool) yesorno;


+ Scheduledtimerwithtimeinterval: Target: selector: userinfo: repeats:


+ (Nstimer *) scheduledtimerwithtimeinterval :( nstimeinterval) Ti target :( ID) atarget selector :( SEL) aselector userinfo :( ID) userinfo repeats :( bool) yesorno;


Create a new nstimer object and time table, and call an instance method cyclically in the current default mode.


+ Timerwithtimeinterval: Invocation: repeats:

+ (Nstimer *) timerwithtimeinterval :( nstimeinterval) Ti invocation :( nsinvocation *) Invocation repeats :( bool) yesorno;


+ Timerwithtimeinterval: Target: selector: userinfo: repeats:


+ (Nstimer *) timerwithtimeinterval :( nstimeinterval) Ti target :( ID) atarget selector :( SEL) aselector userinfo :( ID) userinfo repeats :( bool) yesorno;


-Initwithfiredate: interval: Target: selector: userinfo: repeats:


-(ID) initwithfiredate :( nsdate *) date interval :( nstimeinterval) Ti target :( ID) T selector :( SEL) s userinfo :( ID) UI repeats :( bool) rep;

Scheduledtimerwithtimeinterval :( nstimeinterval) seconds

Reserve a timer and set a time interval.

Indicates the input of a time interval object, in seconds, a value greater than 0 of the floating point type. If the value is <0, the default value is 0.1.

Target :( ID) atarget

Indicates the sent object, such as self.

Selector :( SEL) aselector

Method selector. During the interval, select to call an instance method.

Userinfo :( ID) userinfo

This parameter can be set to nil. When the timer fails, the specified object retains and releases the timer.

Repeats :( bool) yesorno

When yes, the timer continues until it becomes invalid or is released. When no, the timer will be sent cyclically once and then become invalid.

Invocation :( nsinvocation *) Invocation

Start Timer


-Fire

Stop Timer


-Invalidate

Timer settings


-Isvalid


-Firedate


-Setfiredate:


-Timeinterval


-Userinfo

Nstimeinterval class: A floating point number used to define the second

Example:

The iPhone provides us with a very long timer nstimer

He can complete any scheduled function:

It's easy to use. Just remember the three elements. The three elements are: Time Interval nstimeinterval floating point, event proxy

Delegate and event processing method @ selector ();

+ (Nstimer *) scheduledtimerwithtimeinterval :( nstimeinterval) Ti target :( ID) atarget selector :( SEL) aselector userinfo :( ID) userinfo repeats :( bool) yesorno;
To initialize a time timer.

The following is a simple example.

Initialize a Timer:

-(Void) inittimer

{

// Time Interval

Nstimeinterval timeinteger = 1.0;

// Timer

Nstimer showtimer = [nstimer scheduledtimerwithtimeinterval: maxshowtime

Target: Self

Selector: @ selector (handlemaxshowtimer :)

Userinfo: Nil

Repeats: No];

}

// Trigger the event

-(Void) handlemaxshowtimer :( nstimer *) thetimer

{

Nsdateformatter dateformator = [[nsdateformatter alloc] init];

Dateformator. dateformat = @ "yyyy-mm-dd hh: mm: SS ";

Nsstring * Date = [dateformater stringfromdate: [nsdate date];

If ([date isequaltostring: @ "23:59:59"])

{

Uialertview * Alert = [[uialertview alloc] initwithtitle: title_name

Message: @ "now it's a new day! "

Delegate: Self

Ancelbuttontitle: Nil

Otherbuttontitles: confirm_title, nil];

[Alert show];

[Alert release];

}

[Data release];

[Dateformator release];

}

Another example is provided: Box race

-(Void) viewdidload

{

 

[Super viewdidload];

Cgrect workingframe;

 

Workingframe. Origin. x = 15;

Worker frame. Origin. Y = 400;

Workingframe. Size. width = 40;

Workingframe. Size. Height = 40;

 

For (INT I = 0; I <6; I ++)

{

Uiview * myview = [[uiview alloc] initwithframe: workingframe];

[Myview settag: I]; // mark the square

[Myview setbackgroundcolor: [uicolor bluecolor];

 

Workingframe. Origin. x = workingframe. Origin. x + workingframe. Size. Width + 10;

[Self. View addsubview: myview];

}

}

 

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.