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 the array does show up in the table view.
How can I do this just using bindings
?
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 the array does show up in the table view.
How can I do this just using bindings
?
I think you'll need to use a TableViewDelegate and implement
- (NSIndexSet *)tableView:(NSTableView *)tableView
selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes
While the previous answers work, this is another option which I prefer to use:
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex
{
return NO;
}
I think
- (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView
{
return NO;
}
is better than
- (NSIndexSet *)tableView:(NSTableView *)tableView selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes
Swift 4.0
func tableView(_ tableView: NSTableView, shouldSelectRow row: Int) -> Bool {
return false
}
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...
Using Binding:
Another approach is select 'empty' in the list of checkboxes corresponding to 'Selection' in Attribute Inspector of table view. This will not select any rows by default.
In addition to this, make the highlight option to 'None'.
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.
© 2022 - 2024 — McMap. All rights reserved.