美文网首页iOS DeveloperiOS点点滴滴
is modifying attributes returned

is modifying attributes returned

作者: onehao16 | 来源:发表于2016-08-15 15:31 被阅读84次

在我们的控制台中会报这样的错误:

This is likely occurring because the flow layout subclass  XXX(类名) is modifying attributes returned by UICollectionViewFlowLayout without copying them

先上图吧!


控制台报错.png

看到这个错误真心很不舒服,作为有强迫症的程序员来说就该去想办法解决这样问题了,我查阅资料找到了出错原因如下:

 override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {

      let array = super.layoutAttributesForElementsInRect(rect)!
      return array
  }
自定义CollectionView报错原因.png

解决方案如下:

  override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? {

          let array = NSArray(array: super.layoutAttributesForElementsInRect(rect)!, copyItems: true) as! [UICollectionViewLayoutAttributes]
    return array
  }

现在再运行你的程序 看看是不是很干净了呢 ?
喜欢就点一个一下喜欢吧 谢谢!

相关文章

网友评论

    本文标题:is modifying attributes returned

    本文链接:https://www.haomeiwen.com/subject/ckpusttx.html