Reuse of CollectionViewCell with ShinobiChart inside


#1

Hi,

I’m working aon an iOS App which uses Shinobicharts inside UIColectionViewCells. These cells can look very different, driven by the data provided.
For example the Chart can have one or two line sieries oder one line and one colum series or use a pie chart. All cells are self sizng with autolayout.

What I do is make a configure call inside of for every cell.
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

So my CollectionViewCell classes know how to configure and fulfill the SChartDatasource protocol.
Everything wokrs fine until cells get reused. Inside cell classes  overwroter prepareForReuse and do this:

    [self.chartViewreloadData];
     [self.chartViewredrawChart];

The new cell data is set at that moment.

Bute what happens is the sometime (only with fast scolling) the reused cell is totaly broken. The data draw by ShinobiChart is completly wrong - not reused or something I can explain. If that issue happens it will reproduce on every redrawing.

What am I doing wrong? Is something special about reusing UICollectionViewCells? Can I reset ShinobiChartView fully?

Thanks for help,
 Kai


#2

Greetings Program!

>> Quote:
>> So my CollectionViewCell classes know how to configure and fulfill the SChartDatasource protocol.

By this I’m assuming you’ve subclassed UICollectionViewCell for each of the charts.

In prepareForReuse, you should only be resetting the data; either to nil or a new instance (you shouldn’t need to call redrawChart).

...
@property (nonatomic, strong) NSMutableArray *data;
...


- (id)initWithFrame:(CGRect)frame {

    self = [super initWithFrame:frame];
    if (self) {
	[self configureChart];
    }

    return self;
}

-(void)layoutSubviews
{
	[super layoutSubviews];

	// Assuming that the data was set in the UICollectionViewDelegate method willDisplayCell
	// or cellForItemAtIndexPath, all that needs to be done is have the chart reload the data.
	// Or, you could set the data and call reloadData together from the delegate method.
	[chart reloadData];
}

-(void)prepareForReuse{
    [super prepareForReuse];

    // Reset the data.
    data = [[NSMutableArray alloc] init];

    [chart reloadData];
}

Wg


#3

I finally found my problem! Whe I get a resused cell axis won’t reconfigure with new data / chart type. I had to remove / update them by hand.
When I do this, everything works fine.


#4

What did you have to do to remove/update them manually?

I keep getting a **[ChartCategoryAxis transformValueToInternal:]: message sent to deallocated instance **when I reload the chart after replacing the axis.


#5

Greetings Program!

Where/how are you replacing and reloading the axis? In prepareForReuse?

Wg