2011-01-26 31 views
0

我目前與NSOutlineView項目運作單元...選擇文本(內容),而不是用的NSCell

我使用,當然的NSCell(S)和我需要讓選擇的能力文本里的單元格... 或至少...防止選擇(和突出顯示)的細胞...

我搜索IB的所有選項,但找不到合適的...

有沒有一種方法,以編程方式或不是,以防止選擇/突出顯示單元格,也不讓用戶選擇單元格內容?

感謝=)

回答

2

這不是太大的NSCell相關的,也許你正在尋找你的委託實施outlineView:shouldSelectItem:

在NSCell上,setEnabled:NO也可能有幫助。從文檔:

setEnabled:(BOOL)flag

禁用單元的文本被改變成灰色。如果一個單元格被禁用,它不能被突出顯示,不支持鼠標跟蹤(因此不能參與目標/動作功能),並且不能被編輯。但是,您仍然可以通過編程方式更改已禁用單元的許多屬性。 (該的setState:方法,例如,仍然有效。)

+0

謝謝:)我認爲這是正確的方式:)但是在單元格中選擇文本呢? – PofMagicfingers 2011-01-26 20:41:35

+0

更新了答案,也許它是你所需要的:P – sidyll 2011-01-26 21:01:05

0

嘗試設置:

cell.selectionStyle = UITableViewCellSelectionStyleNone; 

您也可以嘗試重寫highlightSelectionInClipRect :,但我不能完全肯定這會工作。

+0

除了iOS和UITableViewCell :)我在談論Mac OS中的NSCell :) – PofMagicfingers 2011-01-26 20:40:33

0

我們來看一個快速示例,如下面的大綱視圖。有3列:firstName,lastNamefullName

enter image description here

在這個特殊的例子,假設我們希望只允許firstNamelastName爲可編輯,而fullName(這是有可能從firstNamelastName派生)不是。您可以通過選中或取消選中表格列的可編輯複選框來在Interface Builder中對其進行設置。要做到這一點,請在其中一個表列(不是標題,但在大綱視圖內)上點擊3次;這首先選擇NSScrollView,那麼NSOutlineView,那麼NSTableColumnenter image description here

您可以設定的屬性如下所示:

enter image description here

enter image description here

enter image description here

那通過爲t設置默認的可編輯值來提供一個開始他整個專欄。如果你需要在一個特定的行項目值是否應該爲可編輯或沒有更多的控制,你可以使用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; 
} 
相關問題