Using variable heights with NSFetchedResultsController?

What's the best way to create / use my model and NSFetchedResultsController so that I can use a table with variable height cells? Calculating the height is expensive (and requires access to model data), so I cache the value in my model. However, I know that the tableview will ask for the heights of all visible cells.

My current thought is that I will limit the number of results and let the user get large numbers themselves to prevent overloading.

My problems, however, are that my lines contain about 200 bytes of each of the relevant data. It's true that parsing 200 lines will take about 20k, but what if I want to display 20,000? I will blame 2MB of raw data for setting the height of the cells.

There is one attribute that takes up about 90% of the data. This means that I can store the main entity up to 20 bytes per line. Should I keep it in a separate object so I can avoid it if necessary?

One final note: cell height is completely dynamic and depends on the content. If there were only a few possible options, it would be much easier.

+2


source to share


2 answers


Fortunately, with the iPhone SDK 3.1, we can track the sql calls used by Core Data. It turns out that for small amounts of data (like 200 bytes per cell) the performance is much better if you store it all in the same object. For the example above (with 20,000) Core Data cells can execute 2,000 additional queries very well to get the required data, and the overhead of fetching becomes troublesome. It is best to use dosing at this stage to speed up the process.



0


source


If you can enumerate cell types based on the content you pour into the cell, and keep the cell type in your data model, you can do a tree switch

- case

to return the standard, pre-calculated heights based on each cell.



0


source







All Articles