NSTableHeaderView evita que el diseño automático cambie el tamaño de la vista de desplazamiento en una vista dividida

The question: Why having a header view prevents scroll view from being resized by auto layout?

I'm trying to embed my custom view in a scroll view, which in turn is enclosed in a split view. I've created the following view hierarchy using Interface Builder in Xcode 4.5 DP 4, but the same problem seems to happen also in Xcode 4.4.

  NSView (content view of the window)
      NSView (split view panel)
      NSView (split view panel)
          TestView (my custom view)

Now, if TestView provides a NSTableHeaderView (via -headerView) property the split view divider cannot be dragged all the way to bottom (or right) to hide the TestView but stops to the boundary of the initial width or height of the TestView. If the -headerView property returns nil, the divider can be dragged freely.

This can be reproduced every time, just by creating a fresh Cocoa application project, adding the views and running the project. The steps:

  1. Create a new Cocoa Application project
  2. Create TestView class with headerView property which returns a NSTableHeaderView instance.
  3. Edit MainMenu.xib and add a split view
  4. Add custom view and make it TestView
  5. Choose Editor -> Embed in -> Scroll view
  6. Ejecute el proyecto

(No constraints or other Interface Builder menus touched)


@implementation TestView {
    NSTableHeaderView *_header;

- (NSTableHeaderView *)headerView
    if (!_header) {
        _header = [[NSTableHeaderView alloc]
                   initWithFrame:NSMakeRect(0.0, 0.0, 100.0, 17.0)];

    return _header;


Any pointers, what should I do to get the split view divider moving again?

preguntado el 31 de julio de 12 a las 11:07

I have this same problem. I wasn't able to discover exactly what was going on with the layout inspector. It seems that the springs-and-struts layout is being mistranslated to a constraint that keeps the height of the table from shrinking. -

I did file a bug with Apple about this issue. We'll see what, if anything happens. -

same problem with NSTableView, if I switch off table headers, I can resize correctly -

Apple hasn't yet commented or responded to my radar report. -

2 Respuestas

Implement this NSSplitViewProtocol method in a convenient class:

- (BOOL)splitView:(NSSplitView *)splitView shouldAdjustSizeOfSubview:(NSView *)subview {return TRUE;}

Make sure to connect the split view's delegate output the class object.

The split view can now be adjusted to any size.

Respondido 14 Oct 12, 08:10

My solution was to manually remove the autoresizing constraints of the table header:

NSTableHeaderView *headerView = outlineView.headerView;
NSView *headerViewSuperview = headerView.superview;
[headerViewSuperview removeFromSuperview];
headerView.superview.translatesAutoresizingMaskIntoConstraints = NO;
[scrollView addSubview:headerViewSuperview];

Respondido el 15 de enero de 13 a las 07:01

This worked perfectly for me, thanks for taking the time to post it. - Darren Wheatley

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.