首页 > 解决方案 > UICollectionView 补充视图初始化在滚动时被一遍又一遍地调用

问题描述

在我的 UICollectionView 中,我有一个补充标题。一开始一切正常,然后当我使用该应用程序时,看起来我的标题单元格中的 init 方法在我每次滚动它时开始被调用,并且它变得滞后。我可以说出一些错误,因为每次我像这样滚动它时,我的标题内视图上的阴影开始再次附加阴影堆积

这是我设置标题的地方

switch kind {

            case UICollectionView.elementKindSectionHeader:

                let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "feeds", for: indexPath) as! ChangeFeedCell
                header.feedsButton.addTarget(self, action: #selector(showFeeds), for: .touchUpInside)
                header.typeButtonWhole.addTarget(self, action: #selector(changeFeeds), for: .touchUpInside)
                header.topButtonWhole.addTarget(self, action: #selector(changeTopSort), for: .touchUpInside)
                
                feedLabelsDelegate = header
                return header

            case UICollectionView.elementKindSectionFooter:
                let footer = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Footer", for: indexPath) as! LoadingFooterCell
                showLoaderDelegate = footer
                footer.backgroundColor = .clear
                return footer
            default:

                fatalError("Unexpected element kind")
            }

标签: iosswiftuicollectionview

解决方案


推荐阅读