我有一个NSTableView
,我想禁用行选择。
表视图的列绑定到NSArrayController
,并且数组的内容确实显示在表视图中。
我怎么能用bindings
做到这一点?
我想你需要使用TableViewDelegate并实现
- (NSIndexSet *)tableView:(NSTableView *)tableView
selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes
虽然之前的答案有效,但这是我更喜欢使用的另一种选择:
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(NSInteger)rowIndex
{
return NO;
}
我认为
- (BOOL)selectionShouldChangeInTableView:(NSTableView *)aTableView
{
return NO;
}
比...更好
- (NSIndexSet *)tableView:(NSTableView *)tableView selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes
Swift 4.0
func tableView(_ tableView: NSTableView, shouldSelectRow row: Int) -> Bool {
return false
}
作为后人的一个注释......
如果声明selectionIndexesForProposedSelection,那么将忽略shouldSelectRow函数。万一你想知道我为什么我对edSelectRow的编辑没有效果...
使用绑定:
在绑定的情况下,您可以使用Enabled绑定布尔值。 binding inspector
如果样本中的值为true,则可以选择,否则就不会。这样,当所有其他东西都通过绑定完成时,我们不需要使用委托来禁用选择。
使用绑定:
另一种方法是在表视图的Attribute Inspector中与'Selection'对应的复选框列表中选择'empty'。默认情况下,这不会选择任何行。
除此之外,将突出显示选项设为“无”。