Question

I am appending some text on my NSTextView on the screen and so I want user to be able to scroll in the view to see the entire log. But I am not able to have my text view scrolling. Below is my code. Any idea whats wrong here.

NSView *superview = [window contentView];

NSRect scrollViewFrame = NSMakeRect(10, self.window.frame.size.height / 2 - 200, 400, 400);
NSScrollView *scrollview = [[NSScrollView alloc]

                            initWithFrame:scrollViewFrame];

NSSize contentSize = [scrollview contentSize];
[scrollview setBorderType:NSLineBorder];
[scrollview setHasVerticalScroller:YES];
[scrollview setHasHorizontalScroller:NO];
[scrollview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];

NSRect textViewFrame = NSMakeRect(0, 0, contentSize.width, contentSize.height);
self.logTextView = [[NSTextView alloc] initWithFrame:textViewFrame];
[self.logTextView setMinSize:NSMakeSize(0.0, contentSize.height)];
[self.logTextView setMaxSize:NSMakeSize(FLT_MAX, FLT_MAX)];
[self.logTextView setVerticallyResizable:YES];
[self.logTextView setHorizontallyResizable:NO];
[self.logTextView setAutoresizingMask:NSViewWidthSizable];

[scrollview addSubview:self.logTextView];
[superview addSubview:scrollview];
Was it helpful?

Solution

This is fixed. I forgot to set the document view for my scrollview.

[scrollview setDocumentView:self.logTextView];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top