スタンドアロンのCocoaテストアプリに次のコードがあります。
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
NSView *contentView = [window contentView];
NSTextStorage *textStorage = [NSTextStorage new];
NSLayoutManager *layoutManager = [NSLayoutManager new];
NSTextContainer *textContainer = [NSTextContainer new];
[textContainer setHeightTracksTextView:YES];
[textContainer setWidthTracksTextView:YES];
[textStorage addLayoutManager:layoutManager];
[layoutManager addTextContainer:textContainer];
NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame:[contentView bounds]];
[scrollView setHasVerticalScroller:YES];
[scrollView setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
[scrollView setBorderType:NSNoBorder];
NSRect textFrame;
textFrame.origin = NSZeroPoint;
textFrame.size = [NSScrollView contentSizeForFrameSize:[scrollView frame].size hasHorizontalScroller:NO hasVerticalScroller:YES borderType:NSNoBorder];
NSTextView *textView = [[[NSTextView alloc] initWithFrame:textFrame textContainer:textContainer] autorelease];
[textView setAutoresizingMask:NSViewWidthSizable];
[scrollView setDocumentView:textView];
[contentView addSubview:scrollView];
}
NSTextView + NSScrollViewの組み合わせで、関連するオブジェクト(テキストシステムオブジェクトを含む)の階層全体を設定して、すべてがどのように連携するかを確認しようとしています。ただし、これを実行してテキストビューに一連の行を追加し始めると、テキストがビューの高さより長くなるとスクロールしません。NSScrollViewとNSTextViewがお互いを認識していないかのようです。ここですべてを正しく通信させるために、どのような接続が欠落していますか?
編集:はい、これは漏れやすく醜いです。:)これは、ここで何が起こっているのかを判断するためだけに書かれたものであり、本番コードや、これから直接使用するものではありません。約束。