Update a label with speed every x seconds

若如初见. 提交于 2019-12-01 21:00:33

You can schedule the timer like this

NSTimer *myTimer = [NSTimer scheduledTimerWithTimeInterval:YOUR_INTERVAL 
                       target:self 
                       selector:@selector(updateLabel) 
                       userInfo:nil 
                       repeats:YES];

Now below method will get called in every YOUR_INTERVAL (in seconds) periods

- (void) updateLabel {
    myLabel.text = @"updated text";
}

To stop the timer you could call invalidate on the timer object. So you might want to save the timer as a member variable, so that you can access it anywhere.

[timer invalidate];

you are right you have to use NSTimer. You will be calling one method after x seconds and updating the label.

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

-(void)updateLabel
{
    // update your label
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!