I am working on a UITableView implementation that must support 000's of records. I have been utilising UITable InsertRows, DeleteRows, and MoveRows to shuffle around records as required. Performance-wise, this all works well when utilising only the insert/delete. I have found that MoveRows has the undesirable side-effect of scrolling the table to attempt to keep any moved rows in the visible region of the table. When you have thousands of records, this can cause the table to scan across, and hence demand the loading, of a great number of cells.
I have tried various techniques, such as disabling scrolling, in attempts to prevent the change in content-offset - with little success.
One workaround is to forego the MoveRow, and substitute it with an InsertRow/DeleteRow pair. This does indeed work, however at the cost of disjointed animation, and more importantly, loss of row selection.
Can anyone recommend a technique known to have the desired effect here?
==== update ====
I mentioned 'little success'. The success that I did have was in observing that ContentOffset
repositioning was not attempted by the table if ContentOffset
was {0,0}
.
So, my hack was to move to ContentOffset = {0,0}
without animation, batch my updates, then restore the ContentOffset
. It appears that the table pre-calculates whether it will reposition or not, somewhere inside the actual MoveRow
call. So - I can quickly move offset to zero and back again without it being visible to the user. The table then begins the animations.
e.g.
var contentOffset = _table.ContentOffset;
_table.PerformBatchUpdates(() =>
{
_table.MovRows(...);
});
_table.SetContentOffset(contentOffset, false);