Question

I have an NSTextView that is on a view that is the view of an NSCollectionViewItem. I give the user the option to hide the NSTextView and instead bring up an NSView object in its place on the same view.

However, when I run the program with the NSView object hidden and overlapping the NSTextView, scrolling in the NSTextView does not work correctly; The vertical scroll bar is there and adjusts its size accordingly to the size of the content in the NSTextView. However, the actual scrolling only works by highlighting the NSTextView's content and dragging upwards or downwards. What's more is that if I recreate the view without it being connected to an NSCollectionViewItem and NSCollectionView, it scrolls fine. This is an issue that happens not just with the custom view I have overlapping the NSTextView, but with any view object (buttons, image wells, etc) that overlaps an NSTextView, even if the view object is set as hidden.

Why is scrolling only possible when highlighting and dragging upwards or downwards if the NSTextView is being created with NSCollectionView and there is a view object overlapping it?

Was it helpful?

Solution

Well, I have found a solution that makes little sense but seems to work fine. I subclassed NSTextView and overrode mouseEntered with this:

-(void) mouseEntered:(NSEvent *)theEvent {

    NSScrollView *scrollView=(NSScrollView*)self.superview.superview;
    NSScroller *scroller=scrollView.verticalScroller;
    [scrollView setVerticalScroller:nil];
    [scrollView setVerticalScroller:scroller];
}

If anyone has any idea as to why this issue is happening or a better solution and not just a guess-around, please post it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top