简体   繁体   中英

is there timer in ios

I want to create a timer for example to count 2 sec and after each second an nslog type for example 1 sec passed

any suggestion to do that

yes there is NSTimer, use it as -

[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector() userInfo:nil repeats:NO];

What you're after is NSTimer .

Which, I can't not point out, even a cursory search of the framework docs would have turned up. Laziness IS one of the three Virtues of the Programmer , but c'mon.

You can call your NSTimer like this

[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(changeValue) userInfo:nil repeats:YES];

changeValue function can be like

-(void)changeValue{
    NSLog("calling function after every two seconds");
}

You might want to use NSTimer s timerWithTimeInterval:target:selector:userInfo:repeats: method. Point that towards some object that implements a selector which prints your log entries.

Yes, ios having timer which is used for periodically call method or button touchup event. we can use it like following:

[NSTimer scheduledTimerWithTimeInterval:1.0
    target:self
    selector:@selector(Your_target_Method)
    userInfo:nil
    repeats:NO];
NSInteger timer=0;

now call method every 1 sec

-(void)Your_target_Method{

timer=timer+1;

NSLog(@"Timer:%ld",timer);

}

Furthermore, visit https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Timers/Timers.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM