2013-02-06 27 views
1

我在屏幕上的NSTextView上附加了一些文本,所以我希望用户能够在视图中滚动以查看整个日志。但我无法滚动我的文本视图。以下是我的代码。任何想法这里错了什么。在NSTextView上滚动不起作用

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]; 

回答

0

这是固定的。我忘了为我的滚动视图设置文档视图。

[scrollview setDocumentView:self.logTextView];