【问题标题】:CSStickyHeaderFlowLayout in Swift 3Swift 3 中的 CSStickyHeaderFlowLayout
【发布时间】:2017-02-13 14:50:35
【问题描述】:

在我的UICollectionView 中使用了CSStickyHeaderFlowLayout 类(https://github.com/CSStickyHeaderFlowLayout/CSStickyHeaderFlowLayout)。它通过使用 Swift2.3iOS7 中工作。更新到Swift3后,失败了。 错误消息如下。

未捕获的异常:索引路径 ( {length = 2, path = 0 - 0}) 处的补充项目的布局属性从 indexPath: {0, 0} zIndex: 1024 有效: YES kind: UICollectionElementKindSectionHeader to indexPath: {0, 0}

我的代码如下。

let flowLayout = CSStickyHeaderFlowLayout()
    collectionView = UICollectionView(frame: CGRect(x: 0, y: self.navigationController!.navigationBar.frame.size.height+statusBarHeight() ,width: screenWidth,  height: screenHeight-(self.navigationController!.navigationBar.frame.size.height+statusBarHeight())), collectionViewLayout: flowLayout)    

self.collectionView?.register(CollectionParallaxHeader.self, forSupplementaryViewOfKind: CSStickyHeaderParallaxHeader, withReuseIdentifier: "parallaxHeader")

self.headerNib = UINib(nibName: "CSParallaxHeader", bundle: nil)
self.collectionView.register(self.headerNib, forSupplementaryViewOfKind: CSStickyHeaderParallaxHeader, withReuseIdentifier: "header")

fileprivate var layout : CSStickyHeaderFlowLayout? {
    return self.collectionView?.collectionViewLayout as? CSStickyHeaderFlowLayout
}

func onParallaxHeadered(_ count:Int)
{
    if count == 0
    {
        self.layout?.parallaxHeaderReferenceSize = CGSize(width: getScreenWidth(), height: 0)
    }
}

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
    let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "parallaxHeader", for: indexPath) as! CollectionParallaxHeader

    return view
}

我不知道如何解决这个问题。有没有人提出一些建议? 谢谢。

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    我找到了答案here

    代码是

    override func viewDidLoad() {
        super.viewDidLoad()
        if #available(iOS 10.0, *) {
            self.collectionView?.isPrefetchingEnabled = false
        } else {
            //Fallback on earlier versions
        }
    }
    

    【讨论】:

    • 非常感谢。我已将 xcode 的版本回滚到 7.3。当我完成我的工作时,我会尝试你的建议。
    猜你喜欢
    • 1970-01-01
    • 2015-01-18
    • 2015-10-17
    • 1970-01-01
    • 2017-01-18
    • 2017-07-26
    • 2017-04-02
    • 2017-04-09
    • 2016-11-13
    相关资源
    最近更新 更多