Thursday, January 19, 2017

#1 2016-10-20 07:49:53 am

jaspersiegers
Member
From: The Netherlands
Registered: 2006-08-30
Posts: 36

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

Offline

 

#2 2016-10-20 01:57:53 pm

StevenH
Member
Registered: 2016-09-17
Posts: 29

Re: Custom NSView in NSTableView

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/ … rt-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

Last edited by StevenH (2016-10-20 01:59:41 pm)

Offline

 

#3 2016-10-20 02:35:31 pm

jaspersiegers
Member
From: The Netherlands
Registered: 2006-08-30
Posts: 36

Re: Custom NSView in NSTableView

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

- (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;
}

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.

Offline

 

#4 2016-10-20 03:12:16 pm

StevenH
Member
Registered: 2016-09-17
Posts: 29

Re: Custom NSView in NSTableView

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;

Applescript:


--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())

Last edited by StevenH (2016-10-20 03:14:10 pm)

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.036 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)