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
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:
While the previous answers work, this is another option which I prefer to use:
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex
{
return NO;
}
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.
I think you'll need to use a TableViewDelegate and implement
- (NSIndexSet *)tableView:(NSTableView *)tableView
selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes
> Through this by default TableView selection remove from bind inspector
I think
- (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView
{
return NO;
}
is better than
- (NSIndexSet *)tableView:(NSTableView *)tableView selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes