NSTableView cell (CPTextField) values come up empty when accessing them directly.

33 views
Skip to first unread message

Samir Gartner

unread,
Aug 10, 2017, 10:51:43 PM8/10/17
to Cappuccino & Objective-J
Hello guys and gals, I'm implementing a custom view that has a NSTableView bound to an NSArrayController (working with CUP), I did it all programmatically (I don't like to use Xib's that much). I wan't to add an NSByteCountFormatter to the size cell (like in the CUP video). I tried to do it inside the viewForTableColumn delegate method  but unfortunately I cannot access the CPTextField stringValue directly. If I print the dataView it comes up as a CPTextField, and I can see the values there inside the variable _stringValue and _value, but if I try to read them or use them directly they come up empty, although the values do appear inside the table columns.

- (CPView) tableView:(CPTableView) aTableView viewForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
{
 
var dataView = [aTableColumn dataViewForRow:aRowIndex];
 
var aStringValue = [dataView stringValue];
 console
.log(dataView);
        console
.log(aStringValue);

 
return dataView;
}




Can someone please point me to the right direction, either by adding the NSByteCountFormatter in a different way or accessing the values inside the delegate method?

daboe01

unread,
Aug 12, 2017, 1:44:35 AM8/12/17
to Cappuccino & Objective-J
i guess that at this time the cell values are not set yet.
try [dataView setFormatter:yourFormatter

Keary Suska

unread,
Aug 12, 2017, 2:17:59 PM8/12/17
to objec...@googlegroups.com

> On Aug 10, 2017, at 8:28 PM, Samir Gartner <jig...@me.com> wrote:
>
> - (CPView) tableView:(CPTableView) aTableView viewForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
> {
> var dataView = [aTableColumn dataViewForRow:aRowIndex];
> var aStringValue = [dataView stringValue];
> console.log(dataView);
> console.log(aStringValue);
>
> return dataView;
> }

Also, the above is not correct. You would instead:

- (CPView) tableView:(CPTableView) aTableView viewForTableColumn:(CPTableColumn)aTableColumn row:(CPInteger)aRowIndex
{
// use this method //
var dataView = [aTableView makeViewWithIdentifier:@“whatever" owner:self];
// /////////////////
var aStringValue = [dataView stringValue];
console.log(dataView);
console.log(aStringValue);

return dataView;
}


Keary Suska
Esoteritech, Inc.
"Demystifying technology for your home or business"

Samir Gartner

unread,
Aug 19, 2017, 10:03:39 PM8/19/17
to Cappuccino & Objective-J
You were right, thank you!. I thought I had to use
 [CPByteCountFormatter stringFromByteCount:byteCount]
 and set the field value manually.
Reply all
Reply to author
Forward
0 new messages