无法在主线程上更新 UI

Cannot update UI on main thread

我正在尝试更新 UILabel 中的文本,但我无法更改它。

更新由两个按钮之一触发。第一个按钮工作正常,这是它的事件处理程序:

- (void)laterPressedForLocation {
    self.locationLabel.text = @"Location off";
    // works as expected...
}

无论我怎么尝试,第二个按钮都不会更新文本,这是它的事件处理程序:

// ask for location permission....
- (void)acceptPressedForLocation {
    _clLocManager = [[CLLocationManager alloc] init];
    _clLocManager.delegate = self;
   if ([_clLocManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
       [_clLocManager requestWhenInUseAuthorization];
}

// called when location permissions change
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {

   dispatch_async(dispatch_get_main_queue(), ^{
      self.locationLabel.text = @"Location permission updated";
      // always runs, but does not work
   });
}

如果我在文本更改所在的位置放置断点或 NSLog 语句,我会看到代码已执行并且块已完成 - 但文本实际上从未更改。

请注意,此 UILabel 代码中的其他任何地方都没有更改。

如何强制 UI 更新?

我试过这样延迟更新:

[self performSelector:@selector(updateText) withObject:nil afterDelay:0.01f];

但仍然没有任何反应。

更新

我发现了另一个类似的案例,所以我知道它与位置管理器无关 - 有些东西正在阻止 self 执行更新..

父视图有一个按钮,它在带有顽固的 UI 标签的视图上调用 removeFromSuperview,当我按下那个按钮时,什么也没有发生,UI 视图也没有去任何地方。我的所有其他视图仍然工作正常 - 什么会导致一个 UI 视图停止响应 UI 更新?

知道了.. UIView 初始化代码被第二次触发,我正在更改的视图前面有一个重复的视图,看起来更改没有效果。