gpt4 book ai didi

ios - 无法将类型 '[UICollectionViewLayoutAttributes]?' 的值转换为指定类型 'NSMutableArray'

转载 作者:行者123 更新时间:2023-11-28 06:45:59 25 4
gpt4 key购买 nike

我有一个 UICollectionViewFlowLayout 的子类,我已经定义了 layoutAttributesForElementsInRect 方法

在里面我试图制作一个 NSMutable 数组,这样我就可以枚举对象。

代码如下

override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
// I get the error at this line
var attributes : NSMutableArray = super.layoutAttributesForElementsInRect(rect)
}

我不能将 attributes 元素子类化为 UICollectionViewLayoutAttributes,因为我不能用一个 block 来枚举它

最佳答案

如果你想要一个 NSMutableArray 为什么不使用:

var attributes : NSMutableArray = NSMutableArray(array: super.layoutAttributesForElementsInRect(rect))

您现在拥有的代码需要一个 NSMutableArray,但会收到一个 UICollectionViewLayoutAttributes 数组

关于ios - 无法将类型 '[UICollectionViewLayoutAttributes]?' 的值转换为指定类型 'NSMutableArray',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36345794/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com