NSTableView with Dropdown Menu and having Image inside Menu
Yes, is it possible to have:
- A table having two column ( Should be easy)
- One of Cell should have image and that should be selectable from Drop - down menu By googling what i came to know it has to be of type NS开发者_开发问答PopupButtonCell type, but i want only image inside it, no text, How can i do that ?
- The another column would be editable, user should be able to type in that.
it would be great if i can get any reference code to implement the same.
i did it with following way,
In Coloumn 1 select the DataCell and assign it of type NSPopupButtonCell, by default it wouldn't come, you need to select it explicitly.
In the Code add following lines of Code...
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];
Add following code to set the correct MenuItem
- (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]];
}
}
Now only pending this is to append Image inside MenuItem which is not a big deal at all,
Again thanks for Looking at this, let me know if any other approach is there to do so....
精彩评论