So this is my issue :
I've got an an NSTextView
with lots of content in it (white foreground on black background, if that matters), residing in a Sheet (triggered with beginSheet:modalForWindow:
).
The thing is that, when the I'm scrolling, the contents seem to be hidden.
But, when I'm hovering the mouse over the scrollview/textview, the contents are there again.
So, what's that? Why is that happening? How could I avoid this weird behavior?
Screencast : http://www.screencast.com/t/Sqrk2mdB
NSTextView
contents are being populated asynchronously with the output of an NSTask
running in the background.. - Dr.Kameleon 2012-04-04 05:44
I watched your screencast of your problem, and it looks quite similar to an issue I faced not long ago. I had a method that initiated a sheet, something like this (assume the existence of certain values):
- (IBAction)beginSheet:(id)sender
{
[[NSApplication sharedApplication] beginSheet:sheet
modalForWindow:[self mainWindow]
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:self];
}
The sheet didn't contain a text view like yours, but a table view instead. Sometimes the table view would perform perfectly, but other times, its enclosing scroll view would draw its scroll bars incompletely and there would be vast blank areas as an attempt was made to scroll.
I managed to identify that the wonky behavior occurred only when -beginSheet:
was called on a secondary thread.
To remedy this, I took this approach instead:
- (void)beginSheetOnMainThread:(id)sender
{
[[NSApplication sharedApplication] beginSheet:sheet
modalForWindow:[self mainWindow]
modalDelegate:self
didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
contextInfo:self];
}
- (IBAction)beginSheet:(id)sender
{
[self performSelectorOnMainThread:@selector(beginSheetOnMainThread:) withObject:sender waitUntilDone:YES];
}
and the table views behaved consistently, and correctly.
(I subsequently learned that using the dispatch_async() approach with the main queue and a block works quite well, too.)
I apologize for the anecdotal evidence, knowing that this still may not solve your particular problem. But again, having seen your screencast, I found the symptoms quite familiar.