How to update a UI label from a non UI thread in iOS

前端 未结 5 1431
情深已故
情深已故 2021-02-05 07:17

I am new to iOS development, I have plain objective -c class \"MoneyTimer.m\" for running timer, from there i want to update the an UI label with the changing value of timer.

5条回答
  •  被撕碎了的回忆
    2021-02-05 08:04

    Assuming that label lives in the same class:

        if(nsTimerUp == nil){
            nsTimerUp = [NSTimer scheduledTimerWithTimeInterval: 1.0 target:self selector:@selector(countUpH) userInfo:nil repeats: YES];
        [self performSelectorOnMainThread:@selector(updateLabel)
                                               withObject:nil
                                            waitUntilDone:NO];
    
        }
    
    -(void)updateLabel {
        self.myLabel.text = @"someValue";
    }
    

提交回复
热议问题