Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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
Ios 如何延迟加载UICollectionViewCell的特定内容_Ios_Objective C_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

Ios 如何延迟加载UICollectionViewCell的特定内容

Ios 如何延迟加载UICollectionViewCell的特定内容,ios,objective-c,uicollectionview,uicollectionviewcell,Ios,Objective C,Uicollectionview,Uicollectionviewcell,我用UICollectionView实现了一个日历视图,当快速滚动日历视图时,它并不平滑。所以我在考虑是否可以先加载每个单元格的静态内容,然后在加载特定内容后刷新。那么,如何延迟加载每个UICollectionViewCell的特定内容呢 具体来说,在下面的函数中,我将构造每个UICollectionViewCell并返回它。现在我只想构建静态内容,如日期,并延迟加载特定内容,如背景颜色,如果我今天有一个事件,我将更改此单元格的背景,那么我应该在哪里加载特定内容,以及如何仅刷新显示单元格 - (

我用UICollectionView实现了一个日历视图,当快速滚动日历视图时,它并不平滑。所以我在考虑是否可以先加载每个单元格的静态内容,然后在加载特定内容后刷新。那么,如何延迟加载每个UICollectionViewCell的特定内容呢

具体来说,在下面的函数中,我将构造每个UICollectionViewCell并返回它。现在我只想构建静态内容,如日期,并延迟加载特定内容,如背景颜色,如果我今天有一个事件,我将更改此单元格的背景,那么我应该在哪里加载特定内容,以及如何仅刷新显示单元格

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:UICollectionViewCellIdentifier
                                                                                     forIndexPath:indexPath];

    NSDate *date = [self dateAtIndexPath:indexPath];

    cell.dateLabel.text = [date description];

    // This is the part I want to delay, since it's cost.
    if (dataModel.hasEventAtDate(date)) {
        cell.dateLabel.backgroundColor = [UIColor blue];
    }
    return cell;
}

如果单元格需要更新,您可能需要一个实例变量来跟踪:

Boolean cellNeedsUpdate = NO
在cellForItemAtIndexPath中,检查是否需要完全更新单元格:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (cellNeedsUpdate) {
        // fully update the cell
    } else {
        // do partial update
    }
}
跟踪collectionView的结束滚动,然后重新加载collectionView:

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    cellNeesUpdate = !cellNeedsUpdate;
    [collectionView reloadData];
}

你能展示更多你想延迟加载的内容吗?对于延迟,您可以使用dispatch\u Afterhanks,我刚刚更新了我的问题,请查看最新版本您可以在cellForItemAtIndexPath中显示吗?@anhtu再次更新,感谢您的快速回复:您可以在之后尝试使用dispatch\u。但我觉得还是不顺利。