我目前正在使用NsoutlineView的项目中工作...

我当然会使用NSCELL(S),我需要让选择单元格内的文本的能力...或至少...防止单元格的选择(和突出显示)...

我在IB上搜索所有选项,但找不到合适的选择...

是否有任何方法可以通过编程性地防止选择/突出显示单元格,也不让用户选择单元格内容?

谢谢=)

有帮助吗?

解决方案

这与NScell无关,也许您正在寻求实施 outlineView:shouldSelectItem: 在你的代表中。

在Nscell上, setEnabled:NO, ,也可能会有所帮助。从文档中:

setEnabled:(BOOL)flag

残疾人单元的文本更改为灰色。如果禁用单元格,则不能突出显示,不支持鼠标跟踪(因此不能参与目标/动作功能),也不能编辑。但是,您仍然可以通过编程方式更改残疾单元的许多属性。 (例如,SetState:方法仍然有效。)

其他提示

尝试设置:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

您也可以尝试覆盖亮点SelectionClipRect:,但我不确定这将起作用。

让我们以下面的大纲视图进行快速示例。有3列: firstName, lastName, , 和 fullName.

enter image description here

在这个特定示例中,假设我们只想允许 firstNamelastName 可以编辑 fullName (这可能是从 firstNamelastName) 不是。您可以通过检查或取消选中“表列的可编辑”复选框,在接口构建器中设置此功能。为此,请在一个表列上单击3次(不是标题,而是在轮廓视图内);首先选择 NSScrollView, ,然后 NSOutlineView, ,然后 NSTableColumn: enter image description here

您将按以下方式设置属性:

enter image description here

enter image description here

enter image description here

通过为整列设置默认可编辑值,这提供了一个开始。如果您需要更多地控制特定行的项目值是否应该可以编辑,则可以使用 outlineView:shouldEditTableColumn:item: 委托法:

#pragma mark -
#pragma mark <NSOutlineViewDelegate>

- (BOOL)outlineView:(NSOutlineView *)anOutlineView
    shouldEditTableColumn:(NSTableColumn *)tableColumn
               item:(id)item {

    if ([[tableColumn identifier] isEqualToString:@"firstName"] ||
        [[tableColumn identifier] isEqualToString:@"lastName"]) {

        return YES;

    } else if ([[tableColumn identifier] isEqualToString:@"fullName"]) {

        return NO;
    }
    return YES;
}

如果要控制大纲视图中的特定行是否可选(例如,您可以防止选择组项目),则可以使用 outlineView:shouldSelectItem:.

 - (BOOL)outlineView:(NSOutlineView *)anOutlineView shouldSelectItem:(id)item {
    // if self knows whether it should be selected
    // call its fictional isItemSelectable:method:

    if ([self isItemSelectable:item]) {
        return YES;
    }

    /* if the item itself knows know whether it should be selectable
     call the item's fictional isSelectable method. Here we
     are assuming that all items are of a fictional
      MDModelItem class and we cast `item` to (MDModelItem *)
      to prevent compiler warning */

    if ([(MDModelItem *)item isSelectable]) {
        return YES;
    }

    return NO;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top