is modifying attributes returned by UICollectionViewFlowLayout without copying them--Swift在自定义collectionview的flowlayout的时候控制台报错解决方

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

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
  }

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容