is there timer in ios
11,503
Solution 1
yes there is NSTimer, use it as -
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector() userInfo:nil repeats:NO];
Solution 2
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.
Solution 3
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");
}
Solution 4
You might want to use NSTimers timerWithTimeInterval:target:selector:userInfo:repeats:
method. Point that towards some object that implements a selector which prints your log entries.
Author by
AMH
Updated on June 17, 2022Comments
-
AMH almost 2 years
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
-
AMH almost 13 yearstarget:self selector:@selector(printmESSEAGE:) YOU MEAN , WHEN the printmESSEAGE will be caled , after one second or at the end of the interval , how to control the calling time of this function
-
saadnib almost 13 yearsNSTimer will call the specified function in selector after the time interval we pass here.
-
AMH almost 13 yearshow to implement the part of firring certain function every 1 sec for 4 sec interval for example
-
saadnib almost 13 yearsyou have to fire it for every 1 sec, and in that function manage a count that how much time that function executed and after count > 4 call [timer invalidate]; for this you also have to create NSTimer *timer in .h also.
-
Dan Ray almost 13 years@AMH - No, I mean there's lots of documentation that you might want to look at before coming here and asking big broad general questions.
-
Dan Ray almost 13 years@AMH - For that matter, guess what the first google result for "timer in ios" is? Google will get you answers MUCH faster than posting your google search on Stack Overflow.