ArisRS
ArisRS

Reputation: 1394

Update UILabel by timer doesn't work

I have UIView with Label that shows the time like stopwatch. I set the label from a Timer method. Here is the code below:

  ivarTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0
     target:self
     selector:@selector(updateTimer)
     userInfo:nil
     repeats:YES];

My update method looks like this:

  - (void)updateTimer {
     ...
     self.myLabel.text = @"someChangedStr";
  }

It works great. But on the view I have UITableView and If I scroll the TableView, self.myLabel.text stops update. Should I use threads or something else?

Upvotes: 1

Views: 343

Answers (1)

hwaxxer
hwaxxer

Reputation: 3383

You could run your timer on another thread, but you must always do UI updates on the main thread. However, try adding your NSTimer to the UITrackingRunLoopMode so it will still fire when tracking touches on your window.

[[NSRunLoop mainRunLoop] addTimer:ivarTimer
                          forMode:UITrackingRunLoopMode];

Upvotes: 1

Related Questions