我试图抛出以下内容,但不断提出下面的错误。
我试图实现以下的目标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)。
我反对这个问题时所做的是:
在viewDidLoad()中
需要添加以下代码以使用我们的新自定义流布局对象替换默认布局对象:
let carouselLayout = CarouselCollectionViewLayout()
self.collectionView?.setCollectionViewLayout(carouselLayout, animated: true)
设置集合视图:
let layout = self.collectionView!.collectionViewLayout as! CarouselCollectionViewLayout
ps:CarouselCollectionViewLayout是UICollectionViewFlowLayout的子类
通常你会这样做:
let layout = self.collectionView.collectionViewLayout as! LSSwipeToDeleteCollectionViewLayout
您是否确定在初始化集合视图时首先创建了LSSwipeToDeleteCollectionViewLayout
实例并将其设置为collectionViewLayout
方法中的UICollectionView.init(frame:collectionViewLayout:)
参数?