简体   繁体   English

无法转换“[UICollectionViewLayoutAttributes]”类型的值? 到指定类型 'NSMutableArray'

[英]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.

相关问题 无法将类型“ UITableViewCell”的值转换为指定的类型 - Cannot convert value of type 'UITableViewCell' to specified type 无法将 &#39;() -&gt; _&#39; 类型的值转换为指定类型的 UIImageView - Cannot convert value of type '() -> _' to specified type UIImageView 无法将类型“()”的值转换为指定类型“Bool” - Cannot convert value of type '()' to specified type 'Bool' 无法将类型“ NSMutableArray”的值转换为预期的参数类型“ [SKTexture]” - Cannot convert value of type 'NSMutableArray' to expected argument type '[SKTexture]' 无法将NSMutableArray类型的值分配给UIBarButtonItem类型 - Cannot assign value of type NSMutableArray to type UIBarButtonItem 准备segue:无法将'UIViewController'类型的值转换为指定类型'SecondViewController' - Prepare for segue: Cannot convert value of type 'UIViewController' to specified type 'SecondViewController' 无法将类型“[SomeStruct]”的值转换为指定类型“[SomeProtocol]” - Cannot convert value of type '[SomeStruct]' to specified type '[SomeProtocol]' Swift:无法将&#39;[Any]&#39;类型的值转换为指定类型&#39;NSString&#39; - Swift: Cannot convert value of type '[Any]' to specified type 'NSString' 无法转换&#39;NSFetchRequest类型的值 <NSFetchRequestResult> &#39;到指定类型&#39;NSFetchRequest <T> “ - Cannot convert value of type 'NSFetchRequest<NSFetchRequestResult>' to specified type 'NSFetchRequest<T>' 无法将“ NSDictionary”类型的值转换为指定的“ Dictionary”类型 - Cannot convert value of type 'NSDictionary' to specified type 'Dictionary'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM