草庐IT

Collection-hooks

全部标签

ios - 如何创建单列的 Collection View ?

我正在尝试创建一个包含1列的collectionViewfuncnumberOfSectionsInCollectionView(collectionView:UICollectionView)->Int{return1}funccollectionView(_collectionView:UICollectionView,numberOfItemsInSectionsection:Int)->Int{return10}但这没有用。主要问题是我的单元格大小动态变化。那么我可以将列限制为1吗?我需要按行而不是按列加载单元格。 最佳答案

ios - Collection View 单元格中的多行标签在重用后中断

我有一个带有多个UI元素的自定义UICollectionViewCell,在代码中使用AutoLayout设置进行布局。在较大的设备(iPhone6及更高版本)上,一切都按预期工作。然而,在较小的设备上,多行UILabel会中断,但(看起来)只有在重用后才会中断。在初始显示时,第一个单元格如下所示:在单元格滚动出屏幕并再次打开后,它看起来像这样:这些是在标签上设置的约束:descriptionLabel.centerXAnchor.constraint(equalTo:firstButton.centerXAnchor),descriptionLabel.leadingAnchor.c

ios - 如何在 Collection View 中快速设置项目从下到上

我正在制作一个具有固定高度和宽度以及水平滚动方向的CollectionView。一开始我会有1个单元格,我希望它位于CollectionView的右侧而不是左侧,当更多单元格出现时我希望它们堆叠在前一个单元格的右侧,如1-2-3.我搜索了一个答案,但所有类似的问题都是针对objective-c。有什么想法可以用swift做到这一点吗?提前致谢。 最佳答案 问题是,如果您尝试在viewWillAppear中设置CollectionView的contentOffset,则CollectionView尚未呈现其项目。因此self.coll

ios - 如何在一个 View 中添加多个 Collection View

我正在尝试将2个CollectionView合并到同一个View中。我实现了所有内容并注意到在第二个CollectionView中加载的数据与第一个CollectionView相同。这是我正在尝试的代码classDashBoardMainSection1CollectionViewCellClass:UICollectionViewCell{@IBOutletweakvarDashBoardMainSection1CollectionViewImageListingViewOutlet:UIImageView!@IBOutletweakvarDashBoardMainSection1C

ios - 如何为 Collection View 单元格内的 View 添加手势?

我在CollectionView单元格(也有其他View)中添加了一个具有一组images(socialView)的View,必须对其执行普通点击。此点击不应与CollectionView单元格点击相同。我正在考虑每次在CollectionView委托(delegate)方法cellForItemAt中为socialView添加UITapGestureRecognizer。但我想知道这是正确的方法吗?此外,我想获取调用socialView的indexPath/position。lettapGestureRecognizer=UITapGestureRecognizer(target:s

swift - 在 'stringify()' 上引用实例方法 'Collection' 需要类型 'Int' 和 'Stringify' 是等效的

我制作了一个Stringify协议(protocol),将实现该协议(protocol)的类型转换为字符串。protocolStringify{funcstringify()->String}extensionCollectionwhereIterator.Element==Stringify{///changesalltheelementsinthecollectiontoaStringfuncstringify()->[String]{varstrings=[String]()ifletelements=selfas?[Stringify]{forelementinelements

iOS Collection View : how to scroll a cell to the top of the screen

我想知道是否有办法将某个UICollectionViewCell滚动到View的顶部?我尝试了collectionView.scrollToItemAtIndexPath()方法,但不是将单元格滚动到View的顶部,而是将单元格滚动到View的中心。 最佳答案 您可以使用以下代码:#pragmamark-UICollectionViewDelegate-(void)collectionView:(UICollectionView*)collectionViewdidSelectItemAtIndexPath:(NSIndexPath

swift - Collection 和 MutableCollection 上的扩展发生冲突并被 Xcode 声明为冗余

我有一个文件,其中有2个不同的扩展名:extensionMutableCollectionwhereIndices.Iterator.Element==Index{}extensionCollectionwhereIndices.Iterator.Element==Index{}在可变类中,我只有可变的扩展(有意义!对吧?),而在Collection中,我有两个类共有的扩展。问题是我从Swift编译器收到这个警告:Redundantsame-typeconstraint'Self.Index'=='Self.Indices.Iterator.Element'我应该怎么做才能修复它?

ios - 限制一次加载的单元格 Collection View 数量的方法

我在数组中有200个项目,我在设备上运行时传递到CollectionView,它由于内存警告而崩溃。有没有办法根据滚动限制单元格在索引路径的一行。由于下载图像它显示内存警告。如果我跳过下载部分,那么它不会崩溃。funccollectionView(_collectionView:UICollectionView,cellForItemAtindexPath:IndexPath)->UICollectionViewCell{varcell:ProductListCell?=collectionView.dequeueReusableCell(withReuseIdentifier:"Pr

ios - 如何隐藏/取消隐藏 Collection View 中的部分

我有一个CollectionView,这个CollectionView有3个部分:一个BC然后我想隐藏B部分,那么它看起来像:一个C我试过了collectionView.deleteSections(NSIndexSet(index:1))但它崩溃并说:Terminatingappduetouncaughtexception'NSInternalInconsistencyException',reason:'Invalidupdate:invalidnumberofsections.Thenumberofsectionscontainedinthecollectionviewafter