Table View and Data Source

I have a table that is fed by a data source. The data presented in the table is sorted, while of course the source is not.

When I add or change an item in the data source, the selection bar doesn’t stick with the item it was under before. It just sits there at the same point among the viewable rows. I want to make it move as necessary to stick with the same item, no matter how the data change.

But that means I need to compare something to something, and here’s where I get lost. When I’m not using a data source, I just check the selected row before the change, check which datum that corresponds to (since my data and the table are both sorted in the same order), then find that item again after the data is updated, and set the selected row to that item’s place in my data.

When I’m using a data source, and the table is sorted, how do I do the same thing?

-Joe

Hi Jacques,

Thank you for the code!

I must be deeply stupid this week, because I can’t see how to use your code to get the selector bar in the table view to follow the item as it moves around the sorted list. I can see how it would follow the item in the data source. So what am I missing?

One other question - why the delay?

-Joe

Hmm. Well, thank you for the explanation. It seems I just can’t get it to work for me. No errors, but the blue bar in the table view doesn’t move at all.

Thanks anyway,

-Joe