Pregunta

Tengo una vista estable (basada en la vista) que crea una fila;

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
    TaskTableCellView *tableCellView = [[TaskTableCellView alloc] init];
    return tableCellView;
}

-(void) tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row {
    NSView *view = [rowView viewAtColumn:0];
    [view setTranslatesAutoresizingMaskIntoConstraints:NO];
    NSDictionary *views = NSDictionaryOfVariableBindings(view);
    [tableView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[view]|" options:0 metrics:nil views:views]];
    [tableView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[view]|" options:0 metrics:nil views:views]];
}

- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row {
    return 20;
}

Esta fila crea algunas subvistas y asigna algunas restricciones;

- (void)layout {
    [super layout];
    ViewWithBackground *viewWithBackground = [[ViewWithBackground alloc] init];
    viewWithBackground.backgroundColor = [NSColor greenColor];
    [self addSubview:viewWithBackground];

    [viewWithBackground setTranslatesAutoresizingMaskIntoConstraints:NO];
    NSDictionary *views = NSDictionaryOfVariableBindings(viewWithBackground);
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[viewWithBackground]|"
                                                                 options:0
                                                                 metrics:nil
                                                                   views:views]];
    [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[viewWithBackground]|"
                                                                 options:0
                                                                 metrics:nil
                                                                   views:views]];

    [viewWithBackground setContentHuggingPriority:200 forOrientation:NSLayoutConstraintOrientationVertical];
    [viewWithBackground setContentHuggingPriority:200 forOrientation:NSLayoutConstraintOrientationHorizontal];
}


- (void)drawRect:(NSRect)dirtyRect {
    [[NSColor redColor] set];
    NSRectFill(dirtyRect);
    [super drawRect:dirtyRect];
}

La diversión comienza cuando realmente intento editar las restricciones .. ViewWAhbackground es solo un NSVIEW vacío que establece su fondo.Cuando la restricción es | [VerWhbackground] |Para horizontal y vertical, obtengo el resultado esperado - filas verdes.Cuando lo cambo a lo más básico | - [ViewWAhbackground] - |, obtengo un resultado decididamente inesperado: filas rojas, y sin signos de mi vista verde!

¿Hay algún paso adicional que se supone que debe tomar aquí?Mi objetivo es que mi vista en realidad sea una vista ligeramente más pequeña, para falsificar las 'huecos' entre las filas y el espaciado de los bordes de la vista de la tabla.

¿Fue útil?

Solución

En caso de que cualquiera se tropieza con esto .. Resulta que NStablecellView es un poco torneado sin un tamaño mínimo, agregar (>= 10) en la restricción vertical se ocupó del problema.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top