Ios 下载数据后如何在UIcollectionview中插入项

Ios 下载数据后如何在UIcollectionview中插入项,ios,uicollectionview,uicollectionviewcell,Ios,Uicollectionview,Uicollectionviewcell,这里的朋友我使用UICollectionview显示图像,但我的图像来自web服务。 现在的问题是,我从网络上获得了所有数据,但我如何才能在UICollectionview中插入项。 我知道insertItemAtIndexPath方法,但不知道在哪里以及如何使用它。 请帮帮我。 提前感谢。您可以使用委托模式下载数据 委托将阻止实现协议的类完成下载,以便您可以通过使用[YouCollectionView reloadData] 为了显示您的图像,您的collectionView可以基于一个数组,

这里的朋友我使用UICollectionview显示图像,但我的图像来自web服务。 现在的问题是,我从网络上获得了所有数据,但我如何才能在UICollectionview中插入项。 我知道insertItemAtIndexPath方法,但不知道在哪里以及如何使用它。 请帮帮我。
提前感谢。

您可以使用委托模式下载数据

委托将阻止实现协议的类完成下载,以便您可以通过使用
[YouCollectionView reloadData]
为了显示您的图像,您的collectionView可以基于一个数组,例如,代理可以发送一个包含您的图像/url的数组

/*! This delegate method is called when the items have been downloaded. They're then stored into an array.*/
    - (void)didDownloadItems:(NSMutableArray*)responseArray{
        _imgArray = responseArray;
        [yourCollectionView reloadData];
    }
然后在您的:
(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath

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

    static NSString *cellIdentifier = @"Cell";
    UICollectionViewCell *cell = [yourCollectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

    // Retrieve the img
    UIImage *img = [_imgArray objectAtIndex:indexPath.row];

   //do your stuff with the img

    return cell;
}

感谢您的回复,我正在这样做,但问题是我需要根据从web服务获取的新映像数组插入单元格运行时。那我怎么做呢?