使用自动调整单元格设置UICollectionView后出现异常

问题描述 投票:3回答:1

我仔细地跟着那个exemple来转换我的collectionView,使用动态高度同时使用Nibs。

viewDidLoad中设置estimatedItemSize之后:

override func viewDidLoad() {
    super.viewDidLoad()
    if let layout = self.collectionView.collectionViewLayout as? UICollectionViewFlowLayout {
        layout.estimatedItemSize = UICollectionViewFlowLayoutAutomaticSize
    }
}

我得到这个例外:

2017-09-14 16:03:06.686930-0400 ClientCenterApp[404:48958] *** Assertion failure in -[_UIFlowLayoutSection computeLayoutInRect:forSection:invalidating:invalidationContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3600.7.47/UIFlowLayoutSupport.m:823
2017-09-14 16:03:06.689177-0400 ClientCenterApp[404:48958] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionViewFlowLayout internal error'

任何人都知道为什么?

ios swift uicollectionview
1个回答
2
投票

这解决了我的问题:

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    collectionView.collectionViewLayout.invalidateLayout()
}
© www.soinside.com 2019 - 2024. All rights reserved.