2011-09-02 33 views
17

Tengo un NSTableView y quiero deshabilitar la selección de fila.NSTableView - Desactivar selección de fila

Las columnas de la vista de tabla están vinculadas a NSArrayController y el contenido de la matriz aparece en la vista de tabla.

¿Cómo puedo hacer esto simplemente usando bindings?

Respuesta

21

creo que tendrá que utilizar un TableViewDelegate e implementar

- (NSIndexSet *)tableView:(NSTableView *)tableView 
    selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes 
+0

Probablemente, pero esperaba que esto no sería el caso ... – ericg

+0

{return 0 ; } ¿Supongo? Parece funcionar. –

13

Creo

- (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView 
{ 
    return NO; 
} 

es mejor que

- (NSIndexSet *)tableView:(NSTableView *)tableView selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes 
+2

Puede leer en el archivo de encabezado: "Para un mejor rendimiento y un mejor control sobre la selección, debe usar tableView: selectionIndexesForProposedSelection :." – Stephan

14

Si bien las respuestas anteriores funcionan, esto es otra opción que prefiero usar:

- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex 
{ 
    return NO; 
} 
+0

Este es en realidad el método que desearía si desea deshabilitar algunas filas y no seleccionar otras –

0

Como nota a la posteridad ...

Si se declara selectionIndexesForProposedSelection, entonces shouldSelectRow se tendrá en cuenta la función. Sólo en caso de que se esté preguntando como lo hice por eso mis ediciones a shouldSelectRow no tuvieron ningún efecto ...

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/NSTableViewDelegate_Protocol/index.html#//apple_ref/occ/intfm/NSTableViewDelegate/tableView:selectionIndexesForProposedSelection:

Cuestiones relacionadas