he el código siguiente en una aplicación de prueba de cacao autónomo:NSTextView dentro de un NSScrollView no se desplaza :(
- (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];
}
Estoy intentando configurar toda la jerarquía de objetos involucrados (incluyendo el text system objects) en una combinación NSTextView + NSScrollView solo para ver cómo funciona todo junto. Sin embargo, cuando ejecuto esto y comienzo a agregar un grupo de líneas a la vista de texto, no se desplaza cuando el texto se alarga más de lo que se ve. alto. Es como si el NSScrollView y el NSTextView no se conocieran. ¿Qué conexiones me faltan para que todo aquí se comunique correctamente?
EDITAR: Sí, esto es agujereado y feo. :) Esto fue escrito solo para tratar de determinar qué está pasando aquí, no el código de producción ni nada que vaya a usar directamente otra vez. Promesa.
De hecho, no lo hice. Y parece que esa fue la respuesta. :) ¡Gracias! – Sean
Eso y -setHeightTracksTextView: necesitaba ser NO. – Sean
I * sabía * Estaba olvidándome de uno, pero no tuve tiempo para una búsqueda exhaustiva. :-) –