使用 NSCell 选择文本(内容)而不是单元格
我目前正在一个带有 NSOutlineView 的项目中工作...
当然,我使用 NSCell,并且我需要能够选择单元格内的文本... 或者至少...阻止选择(并突出显示)单元格...
我搜索了 IB 上的所有选项,但找不到正确的选项...
是否有一种方法(无论是否以编程方式)阻止选择/突出显示单元格,也不让用户选择单元格内容?
谢谢 =)
I'm currently working in a project with a NSOutlineView...
I use, of course, NSCell(s) and I need to let the ability to select text inside the cell...
Or at least... prevent the selection (and highlight) of the cells...
I search all options on IB, but can't found the right one...
Is there a way, programmatically or not, to prevent selection/highlighting of cell, nor let user select cell content ?
Thanks =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这与 NSCell 没有太大关系,也许您希望在委托中实现
outlineView:shouldSelectItem:
。在 NSCell 上,
setEnabled:NO
也可能有帮助。来自文档:setEnabled:(BOOL)flag
禁用单元格的文本更改为灰色。如果单元格被禁用,则它无法突出显示,不支持鼠标跟踪(因此无法参与目标/操作功能),并且无法编辑。但是,您仍然可以通过编程方式更改禁用单元格的许多属性。 (例如,setState: 方法仍然有效。)
That's not much NSCell related, maybe you're looking to implementing
outlineView:shouldSelectItem:
in your delegate.On the NSCell,
setEnabled:NO
, may help too. From the documentation:setEnabled:(BOOL)flag
The text of disabled cells is changed to gray. If a cell is disabled, it cannot be highlighted, does not support mouse tracking (and thus cannot participate in target/action functionality), and cannot be edited. However, you can still alter many attributes of a disabled cell programmatically. (The setState: method, for instance, still works.)
尝试设置:
您也可以尝试覆盖highlightSelectionInClipRect:,但我不完全确定这会起作用。
Try setting:
You could also try overriding highlightSelectionInClipRect:, but I'm not totally sure this will work.
让我们举一个简单的例子,如下面的大纲视图。有 3 列:
firstName
、lastName
和fullName
。在此特定示例中,假设我们只想允许
firstName
和 < code>lastName 可编辑,而fullName
(可能源自firstName
和lastName
)则不可编辑。您可以通过选中或取消选中表列的可编辑复选框来在 Interface Builder 中进行设置。为此,请在表列之一(不是标题,而是大纲视图内部)上单击 3 次;首先选择NSScrollView
,然后选择NSOutlineView
,然后选择NSTableColumn
:您可以设置如下属性:
首先为整个列设置默认的可编辑值。如果您需要更多地控制特定行的项目值是否可编辑,可以使用outlineView:shouldEditTableColumn:item:委托方法:
如果您想控制大纲中的特定行是否可编辑视图是可选的(例如,您可以阻止选择组项目),您可以使用
outlineView:shouldSelectItem:
。Let's take a quick example like the outline view below. There are 3 columns:
firstName
,lastName
, andfullName
.In this particular example, let's say we want to only allow
firstName
andlastName
to be editable whilefullName
(which is potentially derived fromfirstName
andlastName
) is not. You could set this up in Interface Builder by checking or unchecking the editable checkbox for the table column. To do that, click 3 times on one of the table columns (not the header, but inside the outline view); this first selects theNSScrollView
, then theNSOutlineView
, then anNSTableColumn
:You'd set the attributes like the following:
That provides a start by setting a default editable value for the entire column. If you need more control over whether a particular row's item value should be editable or not, you can use the
outlineView:shouldEditTableColumn:item:
delegate method:If you want to control whether a particular row in the outline view is selectable (for example, you could prevent selection of a group item), you can use
outlineView:shouldSelectItem:
.