If you implement the delegate methods you can interact with the cell/view when it is displayed and force the folder or based on content/type any other image.
How do I add a static NSFolder image to a cocoa bindings table
-
09-10-2022 - |
Frage
I have a table that gets it's values from core data and is added via cocoa bindings. The values that are printing out in the table are folder names.I would like to have a NSFolder printed out to the left of each folder name. I started off with a simple one column table to make sure my cocoa bindings work, and they do:
After that I tried addin a second column, then I added an image cell to that new column, rearranged the columns, and set image cell's image to NSFolder:
When I change the image cell's image to NSFolder, nothing happened, not even in the interface builder. The icon remained an Xcode icon. And when I ran the build command, there was just a blank space to the left of the folder name.
From there I tried going back to one column and adding an image & Text Table Cell View but I couldn't even get the cocoa bindings to work with that.
So how do I just print display a static NSFolder on the left hand side of each of the folder's names?
Edit: This is what I'm trying to achieve:
Edit #2
I tried implementing the NSTableViewDelegate and adding the following method:
- (NSView *)tableView:(NSTableView *)tableView
viewForTableColumn:(NSTableColumn *)tableColumn
row:(NSInteger)row
{
NSTableCellView *cellView = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
if ([tableColumn.identifier isEqualToString:@"FolderImageColumn"]) {
cellView.imageView.image = [[NSWorkspace sharedWorkspace] iconForFileType:NSFileTypeForHFSTypeCode(kGenericFolderIcon)];
return cellView;
}
return cellView;
}
But now I'm getting completely blank rows. They're clickable and they load the data on the right hand side, but they're completely blank.
Lösung