문제

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
도움이 되었습니까?

해결책

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];
    });
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top