overridefunclayoutAttributesForElementsInRect(rect:CGRect) -> [UICollectionViewLayoutAttributes]? {
letarray: [UICollectionViewLayoutAttributes] =super.layoutAttributesForElementsInRect(rect)!
returnnewArray
}
在程序不崩潰的情況下出現錯誤日志
Logging only once for UICollectionViewFlowLayout cache mismatched frame
This is likely occurring because the flow layout subclass PhotoDemo.LJFFlowLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them
開始很納悶,然后在這個方法中重新創建數組去承接上面的返回值,還是會有崩潰的日志,用這個方法可以解決
但是不知道究竟是為什么,希望有大神看見了可以幫忙回答下
overridefunclayoutAttributesForElementsInRect(rect:CGRect) -> [UICollectionViewLayoutAttributes]? {
letarray: [UICollectionViewLayoutAttributes] =super.layoutAttributesForElementsInRect(rect)!
//換了一個數組的初始化方法完美的解決了問題
letnewArray:[UICollectionViewLayoutAttributes] =NSArray(array: array, copyItems:true)as! [UICollectionViewLayoutAttributes]
returnnewArray
}