Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 文本标签导致UICollectionView快速滚动_Objective C_Performance_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

Objective c 文本标签导致UICollectionView快速滚动

Objective c 文本标签导致UICollectionView快速滚动,objective-c,performance,uicollectionview,uicollectionviewcell,Objective C,Performance,Uicollectionview,Uicollectionviewcell,我对UICollectionView的快速滚动有问题。我的手机由图片和一些文字标签组成 我试着检查是什么导致了这一点,当我禁用设置标签文本时,一切都很顺利,当我为两个以上的标签设置文本时,滚动再次变得急促 有人知道怎么解决吗 这是我的密码: - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

我对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;
}

我找到了UICollectionView的快速滚动解决方案,其中动态设置了许多标签

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


现在,我的UICollectionView正在平滑滚动:)

核心数据中是否存在视图和喜欢的关系?否-所有数据都存储为同一实体的属性使用仪器运行应用程序,查看在哪里花费的时间最多。你在单元格的setter方法中做什么工作吗?如果您注释掉图像处理,它会改进吗?否如果我注释掉图像处理,它不会改进,它只会在我注释掉设置标签文本时改进。。。在仪器中,大部分时间都花在这个方法上-[BGViewController collectionView:cellForItemAtIndexPath:]和-[ResultCellView PrepareForUse]。在我的牢房里,我只在-[didMoveToSuperView]中设置字体、颜色等,而在-[prepareForReuse]中将UIImage设置为零,我不确定。在标签上设置文本不应该引起问题,除非你有很多问题。也许也会显示你的单元格子类代码?