2

我遇到了 UICollectionView 滚动不顺畅的问题。我的单元格由图片和一些文本标签组成。

我试图检查是什么原因造成的,当我禁用为标签设置文本时,一切都很顺利,当我为两个以上的标签设置文本时,滚动又生涩......

有谁知道如何解决它?

这是我的代码:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"ResultCell";
    ResultCellView *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    if ([self.artworksSavedForLater containsObject:indexPath]) {
        cell.saveForLaterButton.selected = YES;
    } else cell.saveForLaterButton.selected = NO;
    Artwork *artwork = [self.dataHelper.fetchedResultsController objectAtIndexPath:indexPath];
    cell.title.text = artwork.title;


    cell.owner.text = artwork.owner;
    cell.fields.text = artwork.fields;
    cell.numberOfViews.text = [NSString stringWithFormat:@"%@",artwork.views];
    cell.numberOfLikes.text = [NSString stringWithFormat:@"%@",artwork.likes];
    cell.numberOfComments.text = [NSString stringWithFormat:@"%@",artwork.comments];
    cell.publishedDate.text = artwork.publishedDate;
    if ([artwork.hasThumbnail boolValue]) {
        dispatch_queue_t downloadQueue = dispatch_queue_create("imagecache", NULL);
        dispatch_async(downloadQueue, ^{
            UIImage *productImage = [UIImage imageWithData:artwork.thumbnail];
            CGSize imageSize = productImage.size;
            UIGraphicsBeginImageContext(imageSize);
            [productImage drawInRect:CGRectMake(0, 0, imageSize.width, imageSize.height)];
            productImage = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
            dispatch_async(dispatch_get_main_queue(), ^ {
                cell.thumbnailImage.image = productImage;
                cell.thumbnailImage.hidden = NO;
            });
        });


    }
    else {
        cell.thumbnailImage.hidden = YES;
        [self startOperationsForPhotoRecord:artwork atIndexPath:indexPath];

    }




    return cell;

我的单元格的代码:

- (void)didMoveToSuperview {
    [super didMoveToSuperview];



    self.title.font = [UIFont fontWithName:@"VerbRegular" size:14.0];

    self.layer.borderColor = [UIColor colorWithWhite:0.19f alpha:1.0f].CGColor;
    self.layer.borderWidth = 1.0f;

    self.layer.rasterizationScale = [UIScreen mainScreen].scale;
    self.layer.shouldRasterize = YES;



}

- (void)prepareForReuse
{
    [super prepareForReuse];
    self.thumbnailImage.image = nil;
}
4

1 回答 1

2

我找到了 UICollectionView 的生涩滚动的解决方案,其中有许多动态设置的标签。

我没有使用标签,而是使用 Miroslav Hudak 在这篇文章中描述的 drawLabel 方法绘制所有 NSString:

如何在drawAtPoint中改变NSString的颜色

现在我的 UICollectionView 滚动顺利:)

于 2013-06-04T15:08:12.693 回答