1

我正在使用 UICollectionView 在 iPad 中显示基于网格的视图。我在屏幕上一次只有 200 个(20 行 x 10 列)单元格,每个单元格只包含一个 UILabel。它在滚动时开始变慢,并且不像在 TableView 中那样平滑。

我不知道滚动性能变慢的原因。我该如何改进?

提前致谢!


我有 3 个集合视图,但主要内容 uicollectionview 是已标记为 2 的那个。这是我的代码

if (collectionView.tag==0) { //This tagged collection view is for Left side selection box

    LeftSelectionBoxItem *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"SelectionCell" forIndexPath:indexPath];

    return cell;
}
else if (collectionView.tag==1){ //This tagged collection view is for to show column names

    TopColumnItem *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ColumnCell" forIndexPath:indexPath];
    cell.columnName.text = [NSString stringWithFormat:@"%@",[self.columnNames objectAtIndex:indexPath.item]];

    return cell;
}
else if (collectionView.tag==2) { //This tagged collection view is for to show main content

    GridItem *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GridCell" forIndexPath:indexPath];
    cell.dataLabel.text = [NSString stringWithFormat:@"%@",[[self.dataModel objectAtIndex:indexPath.section] objectForKey:[self.columnNames objectAtIndex:indexPath.item]]];

    return cell;
}
else {
    return nil;
}
4

1 回答 1

3

拥有很多 UILabel 有时会很昂贵。尝试将它们更改为 CATextLayers,因为它们的开销要少得多。请注意,如果您这样做并使用光栅化,您将需要告诉图层也为视网膜显示设备进行光栅化。

于 2012-12-14T12:36:11.230 回答