Q: In my application when my window becomes the key window or the main window, sometimes it doesn't display itself. What's going on?
A: There is a bug where display sometimes is disabled in a Window when the window becomes key and/or main. The result is that a window (or its delegate) tries to do some drawing in its becomeKeyWindow or becomeMainWindow (or windowDidBecomeKey: or windowDidBecomeMain:) method, and the drawing doesn't happen because some drawer observes that display is disabled.
Here's a workaround. You can do this little dance in either your delegate method or your override of Window's becomeKeyWindow or windowDidBecomeMain.
- windowDidBecomeMain:win
{
BOOL displayWasDisabledForActivation = [NXApp _isInvalid] &&
![win isDisplayEnabled];
if (displayWasDisabledForActivation)
[win reenableDisplay];
/* whatever you do now... */
if (displayWasDisabledForActivation)
[win disableDisplay];
return self;
}
The _isInvalid method is a private method, and as such is undocumented. Calling this ensures that you are in the case where this bug bites. We thought this might be prudent in case there was a different time when you really would like display to be disabled.
Valid for 2.0, 3.0
QA661