BenjaminPrieur / IOStickyHeader

Parallax and Sticky header done right using UICollectionViewLayout
MIT License
196 stars 24 forks source link

warning occurs at runtime #5

Closed hengchengfei closed 9 years ago

hengchengfei commented 9 years ago

Warning:

This is likely occurring because the flow layout subclass eval.IOStickyHeaderFlowLayout is modifying attributes returned by UICollectionViewFlowLayout without copying them

IOStickyHeaderFlowLayout.swift


public override func layoutAttributesForItemAtIndexPath(indexPath: NSIndexPath) -> UICollectionViewLayoutAttributes? {
        let attributes = super.layoutAttributesForItemAtIndexPath(indexPath)
        var frame = attributes?.frame
        frame!.origin.y += (self.parallaxHeaderReferenceSize?.height)!
        attributes?.frame = frame!
        return attributes
}

[http://stackoverflow.com/questions/31771089/when-using-subclassed-collectionviewflowlayout-im-getting-weird-error]()

BenjaminPrieur commented 9 years ago

I can't reproduce your warning. Did you get the warning with the example project or your project? Which version of swift are you using? I updated my pod may be i solved it

hengchengfei commented 9 years ago

XCode7.1 Swift2.1

it occurs in my project.

I appreciate.

Bragegs commented 8 years ago

in layoutAttributesForElementsInRect(rect: CGRect) replace this line var allItems = super.layoutAttributesForElementsInRect(rect)!

with this, removed the warning for me:

var allItems = [ UICollectionViewLayoutAttributes ]() let attributes = super.layoutAttributesForElementsInRect(adjustedRec) for originalAttribute in attributes! { allItems.append(originalAttribute.copy() as! UICollectionViewLayoutAttributes) }