在自定义collectionview的flowlayout的时

2016-07-28  本文已影响611人  ScorpioLiu

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

}

上一篇下一篇

猜你喜欢

热点阅读