Replacing data in a table

Sigh, me again…

So, I have a table connected to an array controller. I want to replace the selected row of data with some new data. If I replace it in the property it doesn’t refresh the table. I’m sure there is a way to tell the table to replace the selected row with the new data but all I can find is commands to add or remove rows from any array controller.

Help?

What have you tried so far?

Did you look up the docs about NSTableView or NSArrayController?

Yep. Read above… I only see add and remove commands for an array controller. Nothing about replacing. Table View seemed less promising.

Does that mean I have to remove the selection and then add the new data at the same point the old selection existed? Perhaps that’s the way to go.

Right now I can add the data directly to a property containing it and then tell the table to replace but that too seems a little burdensome.

It seems there might be a command I am missing to simply replace the selected row of data with the new data. Perhaps not?

For refreshing the table, you can use reloadData. It forces it to reload.

As for replacing entries, there is no such method. You have to either modify the entry itself, or remove then add a new entry.

Any one of these NSArrayController’s methods should be of help:

“ addObject:
“ addObjects:
“ insertObject:atArrangedObjectIndex:
“ insertObjects:atArrangedObjectIndexes:
“ removeObjectAtArrangedObjectIndex:
“ removeObjectsAtArrangedObjectIndexes:
“ remove:
“ removeObject:
“ removeObjects:

But I don’t understand why your table is not refreshing automatically. I never use reloadData, things get added automatically when I use addObject…

I’m not adding an entry… I’m changing one that already exists. Since I can’t replace/modify it, I am changing the data in the list property in the script which apparently doesn’t automatically update the array/table automatically or not immediately. Hence, the reload command.

At this point that’s my approach because I’ve run out of time to play around with this any more. Perhaps if I get bold later I will try to delete and add the replacement data in it’s former position.

For now, I have to move on before I lose my mind.

What are you using exactly? It’s a bit unclear because we don’t have any idea of the way your data is coded (the Model), nor the way it is represented in the interface (the View). So the role of your Controllers is hard to guess.

Are you using a Applescript list? A list of what? values or records?

In order your controller to be aware of your list’s changes, you have to inform the notification system that something has changed into your list. For this, you must put «my» before the name of the object that is changing. Say you want to modify the line 4 of your table view, you have to do:

set item 5 of my dataList to newValue – value is the data you store in a line. NSArrays begin at 0, AS list at 1.

Try this. The controller should reflect your changes.