我试图投出以下内容,但不断地出现下面的错误。
我正在努力实现以下目标c版本,效果很好:
LSSwipeToDeleteCollectionViewLayout是UICollectionViewFlowLayout的一个子类,是在目标C中编写的。
目标C:
LSSwipeToDeleteCollectionViewLayout *layout = (LSSwipeToDeleteCollectionViewLayout *)self.collectionView.collectionViewLayout; 斯威夫特
let layout : LSSwipeToDeleteCollectionViewLayout = (self.collectionView.collectionViewLayout as AnyObject) as! LSSwipeToDeleteCollectionViewLayout
layout.swipeToDeleteDelegate = self无法将“UICollectionViewFlowLayout”(0x111edda00)类型的值转换为“LSSwipeToDeleteCollectionViewLayout”类型(0x11040e3c0)。
发布于 2018-09-10 14:00:05
当我反对这个问题时,我所做的是:
在viewDidLoad()中
需要添加以下代码以将默认布局对象替换为新的自定义流布局对象:
let carouselLayout = CarouselCollectionViewLayout()
self.collectionView?.setCollectionViewLayout(carouselLayout, animated: true)设置集合视图:
let layout = self.collectionView!.collectionViewLayout as! CarouselCollectionViewLayoutps:CarouselCollectionViewLayout是UICollectionViewFlowLayout的子类
发布于 2016-08-15 21:34:36
通常你只会做:
let layout = self.collectionView.collectionViewLayout as! LSSwipeToDeleteCollectionViewLayout
您确定在初始化集合视图时,首先创建了一个LSSwipeToDeleteCollectionViewLayout实例并将其设置为UICollectionView.init(frame:collectionViewLayout:)方法中的collectionViewLayout参数吗?
https://stackoverflow.com/questions/38963200
复制相似问题