Custom NSView in NSTableView

Hi,

For my application I could really need a custom View inside a TableView. The default Cell view isn’t working for me anymore. I’m searching and reading a lot about how to get your own custom NSView within a tableview but can’t really find a answer that I could easily translate to ObjC.
Is there some tutorial?

My first question is can this be done with bindings?

I did find swift ways where one would use a datasource with the method tableView_viewForTableColumn_row_
In this method they’re setting a text field without bindings and I’m scratching my head how to do that with applescriptObjC.

Many thanks in advance!

Jasper

Parts of it have to be done in Object C to make it easier.
Follow this tutorial, it’s easily translatable to ASOC.

http://gentlebytes.com/blog/2011/08/30/view-based-table-views-in-lion-part-1-of-2/

It’s been written for lion but it works in 10.12 too.

Once done you can also implement a custom array controller class to make your items drag & drop able.

Note: Ignore all dealloc an release commands if you are working with ARC

Thanks, that’s a really good tutorial.
I’m stuck at this point:

[format]

  • (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
    NSTableCellView *result = [tableView makeViewWithIdentifier:tableColumn.identifier owner:self];
    Item *item = [self.items objectAtIndex:row];
    result.imageView.image = item.itemIcon;
    result.textField.stringValue = item.itemDisplayName;
    return result;
    }
    [/format]

And especially the part
result.imageView.image = item.itemIcon;
result.textField.stringValue = item.itemDisplayName;
How does that translate into ASOC?
Also how does ASOC know what objects are in the cell view?

Thanks again.

If you want to work with bindings you won’t need this (and the other) delegate function as mentioned in part 2. (See link at the end)
But to answer;


--avoid result and item as words cause they are reserved or use | bars to escape
theResult's imageView's setImage:(theItem's itemIcon())
theResult's textField's setStringValue:(theItem's displayName())