UICollectionView custom flow layout crashes on scrolling
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am creating a custom flowLayout with section headers. here is my flowLayout.swift import UIKit class FlowLayout: UICollectionViewFlowLayout { override func layoutAttributesForElementsInRect(rect: CGRect) -> [UICollectionViewLayoutAttributes]? { // let attributesForElementsInRect = super. var newAttributesForElementsInRect = [UICollectionViewLayoutAttributes]() // unwrap super's attributes guard let attributesForElementsInRect = super.layoutAttributesForElementsInRect(rect) else { return nil } // modify attributes var leftMargin: CGFloat =