I want to make an action when every second is passed, for example I got a label and I want it every second to do this :
theLabel.text = @"Hey";
So, how I'll do it? I think I'll need to use the NSTimer right?
Thanks in Advance
I want to make an action when every second is passed, for example I got a label and I want it every second to do this :
theLabel.text = @"Hey";
So, how I'll do it? I think I'll need to use the NSTimer right?
Thanks in Advance
Just use a NSTimer:
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(doSomething:) userInfo:nil repeats: YES];
And to stop it:
[timer invalidate];
Find the documentation here:
A "plan B" solution:
[self performSelector:@selector(foo) withObject:nil afterDelay:{some time interval}];
-(void)foo
{
//do something..
[self performSelector:@selector(foo) withObject:nil afterDelay:{some time interval}];
}
Yes @kevin you are right NSTimer
is the best
just initialize your timer on did load
NSTimer *timerCounter = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(doMyWork) userInfo:nil repeats: YES]; //make repeats YES
and do the below
-(void)doMyWork
{
theLabel.text = @"Hey";
// Or what ever you want to do
}