self.view setNeedsDisplay和self.view setNeedsLayout无效

我有一个主视图控制器显示在屏幕上,一个类(委托)在后台运行获取位置。 当我得到结果时,我在视图控制器中调用委托方法来更新屏幕上的标签。 我尝试了几种方法,但仍未更新屏幕。

这是方法:

-(void) updateDisplay { NSLog(@"%@",myPosition.currentArea); _area.text = [NSString stringWithFormat:@"area = %@",myPosition.currentShopArea]; //[self.view performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES]; [self.view setNeedsDisplay]; //[self.view setNeedsLayout]; } 

我检查控制台,它显示正确的区域,但在屏幕上仍然显示为null。 我尝试了所有三种方式(上面已注释),但没有一种更新屏幕。

你可以尝试两件事:

  1. 在主线程上调用updateDisplay

     [delegate performSelectorOnMainThread:@selector(updateDisplay) withObject:nil waitUntilDone:YES]; 

    最后,它正在访问UIKit ,所以做得更好;

  2. 如果这没有帮助,请尝试:

     [_area setNeedsDisplay]; 

    在这种情况下,如果建议在主线程上调用该方法。