CPTBarPlot: Do I need to call reloadData after changing bar fill color?

StackOverflow https://stackoverflow.com/questions/21865881

  •  13-10-2022
  •  | 
  •  

Вопрос

I have an iOS app that displays a CPTBarPlot. My bar plot responds to touches by changing the color of the touched bar. I do this by keeping track of the index of the last selected bar in barWasSelectedAtRecordIndex, and then I set the color of the selected bar in barFillForBarPlot to make it a different color from the others. This works fine, but it seems I have to call reloadData every time the selected bar changes in order for the new fill color to take effect. This takes too long because there is a lot of data, making the app feel sluggish.

It seems wasteful to have to reload all the data just to change the color of one bar, so I'm hoping there's a better way, or I'm just doing something stupid.

Here is a simplified version of the relevant code:

-(void)barPlot:(CPTBarPlot *)plot barWasSelectedAtRecordIndex:(NSUInteger)idx
{
    self.selectedIndex = idx

    // Do I have to do this??
    [self reloadData];
}



-(CPTFill *)barFillForBarPlot:(CPTBarPlot *)barPlot recordIndex:(NSUInteger)index
{
    CPTFill *barFill = nil;
    if (index == self.selectedIndex)
    {
        barFill = [CPTFill fillWithColor:redColor];
    }
    else
    {
        barFill = [CPTFill fillWithColor:blueColor];
    }
    return barFill;
}
Это было полезно?

Решение

Yes. The plot caches everything it loads from the datasource including the bar fills. You need to call -reloadData to tell it that new information is available to load.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top