我在Storyboard(iPad)中定义了一个包含UICollectionView
的视图,在视图的底部还有一个UIToolbar
。 在UICollectionView
中,我添加了一个UICollectionViewCell
(由iPadCellCollectionViewCell
类实现),其中包含另一个视图,即Core-Plot图(CPTGraphHostingView
类)。UICollectionView的单元格在滚动后并不总是被刷新
我有一个名为X的类,实现了UICollectionViewDelegate
和UICollectionViewDataSource
。
在类X,我建立我的视图的每个单元(在ViewDidLoad
)核心-散点图和我有以下代码到图形链接到的UICollectionViewCell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString* cellId = @"ChartCollectionId";
iPadCellCollectionViewCell* cell = [self.theCollectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
MyChart* chart = [_charts objectAtIndex:indexPath.row];
cell.hostingView.hostedGraph = chart.barChart;
return cell;
}小区
它工作正常,所有我的图形都正确显示在屏幕上。当用户滚动视图时,会发生该问题,然后一个或多个单元格变为“空白”。我真的不明白为什么。
我已经找到了解决办法,而不是在Interface Builder中UICollectionViewCell
加入CPTGraphHostingView
,我建立它自己和以前的代码变成:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
static NSString* cellId = @"ChartCollectionId";
iPadCellCollectionViewCell* cell = [self.theCollectionView dequeueReusableCellWithReuseIdentifier:cellId forIndexPath:indexPath];
[cell.contentView addSubview:[_hostingViews objectAtIndex:indexPath.row]];
return cell;
}
有了这个代码一切工作正常。有没有任何解释为什么当我用IB添加CPTGraphHostingView
的UICollectionViewCell
时它不起作用?
每次调用方法时调用“addSubview”是个问题吗?没有内存泄漏?
我在哪里查看错误报告? – bandejapaisa