【发布时间】:2016-10-27 11:29:56
【问题描述】:
我正在尝试根据设备的方向更改部分中的项目数。
我通过在 viewWillTransitionToSize 中重新加载整个集合视图并更改 UICollectionView 中的部分数量中的“部分中允许的最大项目”的数量来实现它。
这不是最好的方式,因为我可以看到我们可以加载特定的部分。 如果您能提出更好的解决方案,请分享。
【问题讨论】:
-
你得到了collectionView的可见项的indexPaths。你试过了吗?
-
实际上只有可见的项目才会重新加载
-
我试过这个@Adeel -(void)reloadVisibleSections { NSMutableIndexSet *visibleSections = [NSMutableIndexSet indexSet]; NSArray *arr = [[self.collectionView indexPathsForVisibleItems] valueForKey:@"section"]; for(NSNumber *index in arr) { [visibleSections addIndex:[index unsignedIntegerValue]]; } [self.collectionView reloadSections:visibleSections];当我们旋转设备时会崩溃,可能是因为当我从横向移动到纵向时可见部分的数量增加了。
-
@SanjayPathak 请使用代码和崩溃日志更新您的问题。
标签: ios objective-c uicollectionview