Change value in array controller by typing in table view cell

477 Views Asked by At

So I have a CPTableView with 2 columns. My CPTableView is filled thanks to an Array Controller which is bind with the CPTableView Columns.

I know how to fill, refill the table view, no problem.

My problem is that I want to change the value of a cell and of course, this value must be changed in the array controller, too.

So I enter my new value by double clicking on the cell, enter it. Ok, but the value isn't changed in the array and it's normal because I didn't tell to the array to do it.

But to change the value in the array, I must be able to get the new value that I wrote in the cell to put in the array.

I can't do this or I don't know how to do this.

I tried the CPTableColumn method : dataCellForRow but it doesn't work, the debugger tells me to use dataViewForRow. Ok, I use it, but when I get the cell value, it always return : "Text Cell" the default title set for the cell in IB.

So really I don't know how to do what I want.

3

There are 3 best solutions below

1
Roma On

Try to tell the array that value is changed. And then reload table.

Do this steps: 1)value changed. changing it in the array 2)reloading table (UItableView has function reloadData). And because you bind array with table reloading will automatically update table

3
Alexander Ljungberg On

If you are using a CPTableView properly bound to a CPArrayController, your table cell values should automatically be updated when you edit them and commit the change, through "reverse bindings". Maybe double check that you have bound CPValueBinding of each column.

Take a look at this manual test: Tests/Manual/ArrayController1 in the Cappuccino repository. If I don't remember wrong it implements this.

If that fails you can always do it by hand using this table view delegate method:

tableView:setObjectValue:forTableColumn:row:

Try to add something like this to your table delegate (untested):

- (void)tableView:(CPTableView)tableView setObjectValue:(id)aValue forTableColumn:(CPTableColumn)tableColumn row:(int)aRow
{   
    var name = [tableColumn identifier];

    CPLog.info("Row %d of table column %@ changed to %@.", aRow, name, aValue);
    // ... change actual model here.
}

Take a look at Tests/Manual/TableTest/Editing in the Cappuccino repository for an example of this.

0
Fenkiou On

In fact, it works, I was not on the good way..

To check if my cell value has changed, i looked for it in the 'CPArray' which contains the data. But this array isn't bind to my 'CPTableView', it's the 'CPArrayController' which is bound. So i checked in this one and i saw that the cell value has modified correctly !

Thank you for your time.