我正在编写一个自定义的 AuthenticationPlugin,它有一些动态内容(目前以标签的形式)。我希望能够更新标签以响应事件。
假设以下声明:
parent = SFAuthorizationPluginView (subclass)view = NSView (subclass)NSTextField *label = ...
我编辑标签文本如下(注意:这可以从后台调度队列中执行):
[label setStringValue:@"new text"];
然后我尝试使用以下命令强制更新:
[label setNeedsDisplay:YES];dispatch_async(dispatch_get_main_queue(), ^{ [label setNeedsDisplay:YES]; });[label display];dispatch_async(dispatch_get_main_queue(), ^{ [label display]; });[[label cell] update];dispatch_async(dispatch_get_main_queue(), ^{ [[label cell] update]; });[[label cell] needsDisplay];dispatch_async(dispatch_get_main_queue(), ^{ [[label cell] needsDisplay]; });[view setNeedsDisplay:YES];dispatch_async(dispatch_get_main_queue(), ^{ [view setNeedsDisplay:YES]; });[self updateView];dispatch_async(dispatch_get_main_queue(), ^{ [self updateView]; });[self displayView]dispatch_async(dispatch_get_main_queue(), ^{ [self displayView]; });
但是,我得到了没有动作和闪烁的灰色屏幕的混合(表明我已经引起了异常)。
有任何想法吗?(注意:我将在尝试各种选项时编辑这个问题)