[英]Cannot convert value of type '[UICollectionViewLayoutAttributes]?' to specified type 'NSMutableArray'
I have a class subclass of UICollectionViewFlowLayout and i have defined the layoutAttributesForElementsInRect
method我有一个 UICollectionViewFlowLayout 的类子类,我已经定义了
layoutAttributesForElementsInRect
方法
And inside i am trying to make a NSMutable array so i can enumerate the objects.在内部,我正在尝试创建一个 NSMutable 数组,以便我可以枚举对象。
the code for this is below代码如下
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
// I get the error at this line
var attributes : NSMutableArray = super.layoutAttributesForElementsInRect(rect)
}
i cant subclass the attributes element as UICollectionViewLayoutAttributes as i would not be able to enumerate through it with a block我不能将属性元素子类化为 UICollectionViewLayoutAttributes,因为我无法用块枚举它
If you want an NSMutableArray why don't you use:如果你想要一个 NSMutableArray 为什么不使用:
var attributes : NSMutableArray = NSMutableArray(array: super.layoutAttributesForElementsInRect(rect))
The code you have now expects an NSMutableArray but receives an array of UICollectionViewLayoutAttributes您现在拥有的代码需要一个 NSMutableArray 但接收一个 UICollectionViewLayoutAttributes 数组
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.