0

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

Dr.Kameleon
  • 22,532
  • 20
  • 115
  • 223
  • Are you doing anything with the textview other than setting the text the first time? – sosborn Apr 04 '12 at 05:42
  • @sosborn The `NSTextView` contents are being populated asynchronously with the output of an `NSTask` running in the background... – Dr.Kameleon Apr 04 '12 at 05:44
  • That is probably what is killing you. How often is that updating the text? – sosborn Apr 04 '12 at 05:48
  • @sosborn Well, that happens like 10 times a second. However, my issue is when the output has stopped. So,what's there is there. Nothing's changing. – Dr.Kameleon Apr 04 '12 at 06:07
  • Do you get the same problem if you just set the text once without the NSTask? – sosborn Apr 04 '12 at 06:10
  • @sosborn Haven't tried it to be honest; please, have a look; I updated my initial post with a Screencast so that you can actually SEE what I mean... – Dr.Kameleon Apr 04 '12 at 06:21
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/9665/discussion-between-sosborn-and-dr-kameleon) – sosborn Apr 04 '12 at 06:27
  • possible duplicate of [Appending to NSTextView](http://stackoverflow.com/questions/9993008/appending-to-nstextview) – jscs Apr 04 '12 at 07:02
  • Have you tried doing it without the modal session to see if that's your problem for sure? – Francis McGrew Apr 04 '12 at 12:07
  • @Dr.Kameleon I'm surprised to see this discussion going on after you accepted my answer in the post Iulius Cæsar pointed out. But now that I read that your NSTextView is inside a sheet, let me ask you this: Did you initiate your sheet on the main thread as well? – Extra Savoir-Faire Apr 14 '12 at 00:31
  • @trudyscousin well, I'm obviously confused as far as threads go. Let me try a few things, and I'll let you know.. – Dr.Kameleon Apr 14 '12 at 02:34

1 Answers1

0

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.

Extra Savoir-Faire
  • 6,026
  • 4
  • 29
  • 47