Pregunta

I'm just updating the UILabel, code is

-(void)updateUI
{
    _syncCountLbl.text=[Global retrieveFromUserDefaults:@"dbCountKey"]
    if ([_syncCountLbl.text isEqualToString:@"0"]) {
        [_syncCountLbl setHidden:YES];
    }
    else
        [_syncCountLbl setHidden:NO];
}

I'm calling this method when

In the console it is showing the text, but not updating in UI.

UILabel: 0x166c9900; frame = (39 0; 23 22); text = '3'; clipsToBounds = YES; userInteractionEnabled = NO; layer = <CALayer: 0x166c99a0
¿Fue útil?

Solución

If you are calling your updateUI method from a tread other than the main thread, the UI is not guaranteed to update immediately. It can happen in 20 seconds, 45 seconds or never, depending when the next UI element requests the UI to update.

Try dispatching to the main thread before calling any UIKit code:

-(void)updateUI
{
    dispatch_async(dispatch_get_main_queue(), ^{
        _syncCountLbl.text=[Global retrieveFromUserDefaults:@"dbCountKey"]
        if ([_syncCountLbl.text isEqualToString:@"0"]) {
            [_syncCountLbl setHidden:YES];
        }
        else
            [_syncCountLbl setHidden:NO];
    });
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top