0

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.

Fenkiou
  • 65
  • 1
  • 7

3 Answers3

0

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

Roma
  • 1,107
  • 9
  • 19
  • Of course, i want to do that, but my problem is that i can't change the value in the array because i can't get the new value. – Fenkiou Jun 14 '13 at 06:18
0

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.

Alexander Ljungberg
  • 6,302
  • 4
  • 31
  • 37
  • Ok, thanks, i will check this and i'll tell you if i succeed. – Fenkiou Jun 14 '13 at 13:11
  • I saw that in the example, columns and bindings are created programmatically. I bound my columns with my CPArrayController in IB and it works fine. I don't know why with IB bindings, the CPArrayController isn't aware that a cell value changed.. – Fenkiou Jun 16 '13 at 17:39
  • Should work fine with IB bindings too. If you are confident you've made the bindings properly but they're still not working, please create a minimal test case and submit a bug report here: https://github.com/cappuccino/cappuccino/issues – Alexander Ljungberg Jun 16 '13 at 20:43
0

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.

Fenkiou
  • 65
  • 1
  • 7