NSTableView - Disable Row Selection

后端 未结 8 1482
温柔的废话
温柔的废话 2021-01-01 15:25

I have a NSTableView and I want to disable row selection.

The columns of the table view are bound to a NSArrayController and the content of

相关标签:
8条回答
  • 2021-01-01 15:30

    As a note to posterity...

    If you declare selectionIndexesForProposedSelection, then shouldSelectRow function will be ignored. Just in case you're wondering like I did why my edits to shouldSelectRow had no effect...

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

    0 讨论(0)
  • 2021-01-01 15:32

    While the previous answers work, this is another option which I prefer to use:

    - (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex
    {
        return NO;
    }
    
    0 讨论(0)
  • 2021-01-01 15:33

    Using Binding:

    In case of binding, you can bind a boolean value with Enabled. binding inspector

    if the value in sample is true, it would be selectable or else, it wouldnt be. This way, we dont need to use delegates just for disabling selection when all other stuffs are done through binding.

    0 讨论(0)
  • 2021-01-01 15:38

    I think you'll need to use a TableViewDelegate and implement

    - (NSIndexSet *)tableView:(NSTableView *)tableView 
        selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes
    
    0 讨论(0)
  • 2021-01-01 15:43

    > Through this by default TableView selection remove from bind inspector

    0 讨论(0)
  • 2021-01-01 15:50

    I think

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

    is better than

    - (NSIndexSet *)tableView:(NSTableView *)tableView selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes
    
    0 讨论(0)
提交回复
热议问题