decodeRestorableState for UITableViewController

I'm having a lot of trouble figuring out how to properly implement state restoration for a UITableViewController. I want it to restore to the same position in the table. In my case, the content is dynamic – it doesn't change frequently, but it does change. And the cells are of variable height.


My problem is I don't know quite what data to save in encodeRestorableState, or how to properly decode it. Since the backing data is rather large, and dynamic (populated via an NSMetadataQuery), it doesn't seem feasible to encode *all* the state.


I've tried the simplest – just storing the index path of the topmost visible row, and scrolling to it in decode. I also store placeholder content for all the visible cells. But as soon as the backing data is loaded, it jumps to the wrong position, assumedly because without the backing data it doesn't know what position that cell should be in the scrollView. So I store the calculated height for all the cells up to the highest visible cell, but it still jumps.


I realize this is a pretty open-ended question, but I'm not even sure where to start.


EDIT


after some further digging, I've added restoration IDs to the tableview itself (I had only had one for the tableViewController). This let me remove my manual scrolling to the "proper" row, but it's still off by a bit.


for example, if on close, rows 23..30 are visible, after restoration, it's 28..44.


So it's almost right. But I'm still not sure what I'm doing wrong.

decodeRestorableState for UITableViewController
 
 
Q