0

We have a delegate method which will be called for approximately 20 times in a second. In the delegate method we are updating our UILabel which represents the counter like below mentioned code:

    - (void) counterUpdated:(NSString *) value
    {
        lblCounter.text = [NSString stringWithString:value];

        // [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];

        // [lblCounter setNeedDisplay];

    }

I read similar problems in stack overflow and I implemented the solutions over there and I checked with keeping [lblCounter setNeedDisplay]; method and [[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]]; after updating lblCounter, but it is not working well as expected.

Any pointers?

Amar
  • 13,202
  • 7
  • 53
  • 71
  • You should log lblCounter to make sure it's not nil. Also, no need to use stringWithString: since you're passing in a string. The line should be: lblCounter.text = value; – rdelmar Aug 19 '13 at 15:14
  • Yep, `stringWithString:` is not required here, In the log, Im getting the `lblCounter.text` correctly, but the `lblCounter` is not updating on the screen. – Srikanth Ganji Aug 20 '13 at 02:45
  • What do you mean, that you're getting lblCounter.text correctly? It logs correctly, but you don't see it on screen? – rdelmar Aug 20 '13 at 03:42
  • Correct!! As of now I solved it by ensuring the label updation once in a second – Srikanth Ganji Aug 20 '13 at 11:11

1 Answers1

0

Try using Grand Central Dispatch in order to run this in the main thread:

dispatch_async(dispatch_get_main_queue(), ^{
    lblCounter.text = value; 
});
Natan R.
  • 5,141
  • 1
  • 31
  • 48