I'm writing a custom AuthenticationPlugin which has some dynamic content (currently in the form of labels). I'd like to be able to update the labels in response to events.
Assuming the following declarations:
parent = SFAuthorizationPluginView (subclass)
view = NSView (subclass)
NSTextField *label = ...
I edit the label text as follows (note: this may be executed from the background dispatch queue):
[label setStringValue:@"new text"];
I then try to force an update using the following:
[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]; });
However, I get a mixture of no action and flickering grey screen (indicating I've caused an exception).
Any ideas? (Note: I'll be editing this question as I try various options)
I think all you need to do is put the update of the label in the main queue code like this:
dispatch_async(dispatch_get_main_queue(), ^{
label.text = "Hello World!";
});