重新加载子视图(UICollectionview)

时间:2012-12-19 22:51:56

标签: objective-c ios uicollectionview

在我的ViewController中,我有四个子视图,即UITableView,UICollectionView,View with UILabels和View,显示该项目的预览图像。

通过在tableview中选择一行,我可以更改预览图像和所有标签。但是我无法刷新UICollectionView数据。我尝试了this解决方案,但它只是删除并添加了视图,并且更改了布局和预览图像消失了。

我想要做的就是刷新UICollectionView内容。有没有更简单的方法呢?

3 个答案:

答案 0 :(得分:7)

您是否尝试过[self.collectionView reloadData];

答案 1 :(得分:1)

要仅刷新UICollectionView的一部分,您也可以调用它:

[self.collectionView reloadItemsAtIndexPaths:@[indexPath]]

其中indexPath是您要重新加载的单元格。您也可以在数组中包含多个索引路径。要重新加载整个第一部分,您可以这样称呼:

NSIndexSet *sections = [NSIndexSet indexSetWithIndex:0];
[self.collectionView reloadSections:sections];

答案 2 :(得分:0)

假设您已正确地将UICollectionView连接到dataSource(UICollectionViewDataSource),您可以调用[myCollectionView reloadData]使您的集合视图调用您的dataSource方法(如下所示)以刷新自身:

– collectionView:numberOfItemsInSection:
– numberOfSectionsInCollectionView:
– collectionView:cellForItemAtIndexPath:
– collectionView:viewForSupplementaryElementOfKind:atIndexPath:
相关问题