2011-07-01 20 views
1

具有圖像是的,是有可能有:NSTableView的與下拉菜單和內部菜單

  1. 具有兩個列的表中(應該很容易)
  2. 一個小區的應具有的圖像和這應該是可選擇的從下拉菜單
    通過谷歌搜索我來了解它必須是NSPopupButtonCell類型的類型,但我只想要它裏面的圖像,沒有文字,
    我該怎麼做?
  3. 另一列是可編輯的,用戶應該可以輸入該列。

這將是偉大的,如果我可以得到任何參考代碼來實現相同。

回答

2

我用下面的方式做到了,

在Coloumn 1選擇DATACELL併爲它指定類型NSPopupButtonCell的,默認情況下它不會來,你需要明確地選擇它。

在代碼中添加以下代碼行...

NSTableColumn *option = [pTableColumns objectAtIndex:[pTableView columnWithIdentifier:OPTION_COLUMN_NAME]]; 
NSTableColumn *shortCutItem = [pTableColumns objectAtIndex:[pTableView columnWithIdentifier:SHORTCUT_COLUMN_NAME]]; 

// we want first cell to have the Image & Menu 
//Data type column drop down 
NSPopUpButtonCell *dataTypeDropDownCell = [option dataCell];//[[NSPopUpButtonCell alloc] initTextCell:@"" pullsDown:YES]; 
[dataTypeDropDownCell setBordered:NO]; 
[dataTypeDropDownCell setEditable:YES]; 

NSArray *dataTypeNames = [NSArray arrayWithObjects:@"NULLOrignal", @"String", @"Money", @"Date", @"Int", nil]; 
[dataTypeDropDownCell addItemsWithTitles:dataTypeNames]; 

添加以下代碼來設置正確的菜單項

- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex{ 

    if([[aTableColumn identifier] isEqualToString:OPTION_COLUMN_NAME]){ 
     NSPopUpButtonCell *dataTypeDropDownCell = [aTableColumn dataCell]; 


     [dataTypeDropDownCell selectItem:[ dataTypeDropDownCell itemAtIndex:3]]; 
    } 

} 

現在只待刊發本被追加內部菜單項圖像這是不一個很大的交易,

再次感謝您的看着這個,讓我知道是否有任何其他方法可以這樣做...