Pregunta

Quiero personalizar mi NSTableView. Mis requisitos generales son como sigue:

  • Cada fila tendrá una imagen y un texto; imágenes y texto podrían ser diferentes.
  • Algunas células no podrían tener una imagen.
  • Altura de la fila depende de algún factor externo.
  • Una célula no debe dibujar el fondo, se debe mostrar el fondo NSTableView.

Hasta ahora soy capaz de extraer las células transparentes con un poco de texto. Busqué en Google y descubrió que necesito para personalizar cada célula. Ahora tengo esta pregunta: ¿debería mantener dos columnas o una columna debería estar bien, tener una imagen en el lado izquierdo y el texto adyacente a ese

?

También entiendo que tengo que anular dos métodos:

- (void) drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView

Así que para cada celda, necesito dibujar / construcción de la célula - ¿Puede alguien me guíe? Voy en la dirección correcta? ¿Puedo conseguir un fondo transparente con la altura dinámica con el enfoque anterior?

¿Fue útil?

Solución

Each row will have one image and some text,

So, two columns—one with an image cell, the other with a text field cell.

images and text could be different,

I should hope so.

Some cell might not have the Image,

Not a problem.

Row height is depend upon some external factor,

Be the table view's delegate, and it will ask you what the row's height should be.

Cell shouldn't draw the background,

It won't unless you set it to do so.

it should overall it should show the NSTableView background,

The table view will draw its own background anyway, which you can set in IB's Inspector. If you wanted the table view to not draw a background, you would set its background colors to the clear color.

You don't need a custom cell for any of this.

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