NSTextView : contents are gone when scrolling, and shown when on mouseover

Go To StackoverFlow.com

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

2012-04-04 05:39
by Dr.Kameleon
Are you doing anything with the textview other than setting the text the first time - sosborn 2012-04-04 05:42
@sosborn The NSTextView contents are being populated asynchronously with the output of an NSTask running in the background.. - Dr.Kameleon 2012-04-04 05:44
That is probably what is killing you. How often is that updating the text - sosborn 2012-04-04 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 2012-04-04 06:07
Do you get the same problem if you just set the text once without the NSTask - sosborn 2012-04-04 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 2012-04-04 06:21
let us continue this discussion in chatsosborn 2012-04-04 06:27
possible duplicate of Appending to NSTextViewJosh Caswell 2012-04-04 07:02
Have you tried doing it without the modal session to see if that's your problem for sure - Francis McGrew 2012-04-04 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 - trudyscousin 2012-04-14 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 2012-04-14 02:34


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.

2012-04-18 17:32
by trudyscousin
Ads