无法转换“[UICollectionViewLayoutAttributes] 类型的值?”指定类型 'NSMutableArray'
Cannot convert value of type '[UICollectionViewLayoutAttributes]?' to specified type 'NSMutableArray'
我有一个 UICollectionViewFlowLayout 的 class subclass 并且我定义了 layoutAttributesForElementsInRect
方法
我在里面尝试创建一个 NSMutable 数组,这样我就可以枚举对象。
代码如下
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
// I get the error at this line
var attributes : NSMutableArray = super.layoutAttributesForElementsInRect(rect)
}
我不能将 attributes 元素作为 UICollectionViewLayoutAttributes 进行子class,因为我无法用块来枚举它
如果你想要一个 NSMutableArray 为什么不使用:
var attributes : NSMutableArray = NSMutableArray(array: super.layoutAttributesForElementsInRect(rect))
您现在的代码需要一个 NSMutableArray,但接收到一个 UICollectionViewLayoutAttributes 数组
我有一个 UICollectionViewFlowLayout 的 class subclass 并且我定义了 layoutAttributesForElementsInRect
方法
我在里面尝试创建一个 NSMutable 数组,这样我就可以枚举对象。
代码如下
override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
// I get the error at this line
var attributes : NSMutableArray = super.layoutAttributesForElementsInRect(rect)
}
我不能将 attributes 元素作为 UICollectionViewLayoutAttributes 进行子class,因为我无法用块来枚举它
如果你想要一个 NSMutableArray 为什么不使用:
var attributes : NSMutableArray = NSMutableArray(array: super.layoutAttributesForElementsInRect(rect))
您现在的代码需要一个 NSMutableArray,但接收到一个 UICollectionViewLayoutAttributes 数组