我正在尝试投射以下内容,但不断提出下面的错误。UICollectionViewLayout子类强制转换为子类
我想达到以下,其正常工作的目标C版本:
LSSwipeToDeleteCollectionViewLayout
是UICollectionViewFlowLayout
子类,写在客观C.
目标C:
LSSwipeToDeleteCollectionViewLayout *layout = (LSSwipeToDeleteCollectionViewLayout *)self.collectionView.collectionViewLayout;
Swift:
let layout : LSSwipeToDeleteCollectionViewLayout = (self.collectionView.collectionViewLayout as AnyObject) as! LSSwipeToDeleteCollectionViewLayout
layout.swipeToDeleteDelegate = self
无法将类型'UICollectionViewFlowLayout' (0x111edda00)的值转换为'LSSwipeToDeleteCollectionViewLayout'(0x11040e3c0)。
你好,你的意思是关于你的答案的第二部分? –
当你创建一个集合视图时,你必须设置负责布局的类,它必须是'LSSwipeToDeleteCollectionViewLayout',否则你将得到默认的'UICollectionViewFlowLayout'类,这可能是你的类型转换失败的原因。根据创建集合视图的方式,您可以将布局类设置为在您的笔尖中,或者直接在代码中作为“UICollectionView”初始化程序的参数。 – par