How to create UITableViewCells with complex content to support free scrolling

I am working on a project where I have a tabular view that contains several cells with some pretty complex content. It will be between usually no more than two, but in exceptions up to - say - 30 of them. Each of these complex cells contains a line chart. I am using ios-charts ( https://github.com/danielgindi/ios-charts ) for this.

This View Controller content looks like this: view controller content

The code I'm using to override the cells in the viewController's cellForRowAtIndexPath method looks like this:

var cell = tableView.dequeueReusableCellWithIdentifier("PerfgraphCell", forIndexPath: indexPath) as? UITableViewCell
if cell == nil {
    let nib:Array = NSBundle.mainBundle().loadNibNamed("PerfgraphCell", owner: self, options: nil)
    cell = nib[0] as? FIBPerfgraphCell
}

cell.setupWithService(serviceObject, andPerfdataDatasourceId: indexPath.row - 1)
return cell!

      

and in the cell code I have a "setupWithService" method that pulls data sources from an already existing "serviceObject" and draws a graph like:

func setupWithService(service: ServiceObjectWithDetails, andPerfdataDatasourceId id: Int) {

    let dataSource = service.perfdataDatasources[id]
    let metadata = service.perfdataMetadataForDatasource(dataSource)

    if metadata != nil {
        if let lineChartData = service.perfdataDatasourcesLineChartData[dataSource] {

            println("starting drawing for \(lineChartData.dataSets[0].yVals.count) values")

            chartView.data = lineChartData
        }
    }
}

      

Now the problem: depending on how many values ​​have to be drawn on the graph (from 100 to 2000), the drawing seems to be quite complicated. The user notices that when he scrolls down: as soon as a cell has to be deleted that contains such a complex chart, the scrolling is stuck for a short moment until the chart is initialized. This is, of course, ugly!

In this case, does it make sense NOT to delete cells on demand, but to predefine and hold them in the array as soon as the data needed for the graphical display is received by the view controller and just pull the corresponding cell from that array when needed? Or is there a way to make the initialization of the chart asynchronous so that the cell is there immediately, but the chart appears whenever it is "ready"?

Thank you for your responses!

+3


source to share


1 answer


What you are trying to do will inevitably run into serious performance problems one way or another. Storing all the cells (and their data in memory) will quickly take advantage of your available RAM. On the other hand, reinstalling and rebooting will cause delays on some devices that you are experiencing right now. You'd be better off rethinking your application architecture:

1- Pre-copy your charts and export them as images. Loading images in and out of cells will have much lower performance.



2- Make the table view into a pull down menu where you only show one graph at a time.

Hope this helps!

+4


source







All Articles